<?php
// +----------------------------------------------------------------------
// | CoreThink [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.corethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: jry <598821125@qq.com> <http://www.corethink.cn>
// +----------------------------------------------------------------------
namespace Home\Controller;
use Think\Controller;
/**
 * 用户控制器
 *
 */
class UserController extends HomeController
{
    /**
     * 用户列表
     *
     */
    public function index()
    {
        $usertype = I('get.usertype');
        if ($usertype) {
            $map['usertype'] = $usertype;
        }
        $user_list = D('User')->page(!empty($_GET["p"]) ? $_GET["p"] : 1, 24)
            ->where($map)->order('id desc')->select();
        $page = new \Common\Util\Page(D('User')->where($map)->count(), 24);
        $this->assign('page', $page->show());
        $this->assign('meta_title', '会员');
        $this->assign('user_list', $user_list);
        $this->display();
    }

    /**
     * 用户个人主页
     *
     */
    public function home()
    {
        $uid = I('get.uid');
        if (!$uid) {
            $uid = $this->is_login();
        }
        $user_info = D('User')->where($con)->find($uid);
        if ($user_info['status'] !== '1') {
            $this->error('该用户不存在或已禁用');
        }
        $this->assign('meta_title', $user_info['username'] . '的主页');
        $this->assign('user_info', $user_info);
        $this->display();
    }

    /**
     * 用户个人中心
     *
     */
    public function center()
    {
        $uid = $this->is_login();
       /* $jihuoma['id']=$uid;
        $jihuomazt=D('User')->where($jihuoma)->getField('jh_yq_ma');
        if($jihuomazt==0){
            echo header("Content-Type:text/html;charset=utf-8");
            echo "<!DOCTYPE html><html lang=\"zh-CN\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\"><script src=\"/Application/Home/View/wvc/_Resource/js/jquery.min.js\"></script><script type=\"text/javascript\" src=\"/Application/Home/View/wvc/_Resource/js/bootstrap.min.js\"></script> <link href=\"/Application/Home/View/wvc/_Resource/css/bootstrap.css\" rel='stylesheet' type='text/css' /></head><body class='container-fluid'style=\"background-color: #99cc99;>";
            echo '<div class="container-fluid"><div class="row" style="text-align: center;margin-top: 25%;">';
            echo '<h1>您的账号尚未激活,请输入激活码</h1><form action="/index.php?m=home&c=user&a=jihuoma" method="post" class="form-inline"><div class="form-group"><label for="exampleInputName2">激活码</label><input class="form-control" name="jihuoma" style="" type="text" placeholder="请输入激活码" /> <button type="submit" class="btn btn-danger">立即激活</button></div></form>';
            echo '</div></div></body></html>';
        }else{  */
        $user_info = D('User')->where($con)->find($uid);
        $map['lbw_vipid'] = $uid;
        $map['jiaoyi_zt']=array('neq',9);
        $category_info = D('UserTemppipeiorder')->where($map)->field('id,lbw_order_pipei,jiaoyi_zt,peidui_cishu,creattime,money_total,yipipei_money,total_forever')->limit(50)->select();
        $category_infotwo = D('UserTempskorder')->where($map)->field('id,peidui_status,shoukuan_cishu,lbw_order_sk_id,jiaoyi_zt,creattime,money_total,dt_qb,total_sk,yipipei_money')->limit(50)->select();
        $datacig['name'] = "LBW_TGBZJE_ZD";
        $FK_ZDJE=D('SystemConfig')->where($datacig)->getField('value');
        $datacigt['name'] = "LBW_TGBZJE_ZG";
        $FK_ZGJE=D('SystemConfig')->where($datacigt)->getField('value');
        $datacigf['name'] = "LBW_HDBZ_ZD";
        $SK_ZDJE=D('SystemConfig')->where($datacigf)->getField('value');
        $datacigtg['name'] = "LBW_HDBZ_ZG";
        $SK_ZGJE=D('SystemConfig')->where($datacigtg)->getField('value');
        $this->assign('meta_title', '个人中心');
        $this->assign('user_id', $user_info['username']);
        $this->assign('user_username', $user_info['id']);
        $this->assign('user_time', $user_info['ctime']);
        $this->assign('user_jtmoney', $user_info['user_jt_money']);
        $this->assign('user_pda', $user_info['lbw_paidancount']);
        $this->assign('user_jt_ye',$user_info['user_jt_money']);
        $this->assign('user_dt_ye',$user_info['user_dt_money']);
        $this->assign('user_zd_lx',$user_info['lbw_lixitotal']);
        $this->assign('user_dt_ye',$user_info['user_dt_money']);
        $this->assign('user_viplevel',$user_info['lbw_viplevel']);
        $this->assign('usernametwo',$user_info['username']);
        $this->assign('passwordtwo',$user_info['password']);
        $this->assign('jihuozt',$user_info['jh_yq_ma']);
        $this->assign('fk_zg_je',$FK_ZGJE);
        $this->assign('fk_zd_je',$FK_ZDJE);
        $this->assign('sk_zg_je',$SK_ZGJE);
        $this->assign('sk_zd_je',$SK_ZDJE);
        $this->assign('lbwlist', $category_info);
        $this->assign('userlist',$category_infotwo);
        //提供帮助列表打印
        $pdlist['dk_lbw_vipid'] = $uid;
        $pdlist['sf_jy_status']=array('neq',8);
        $pdlist['sf_jy_status']=array('neq',2);
        $category = D('UserPipeioder')->where($pdlist)->limit(50)->select();
        $i_if=count($category);
        $this->assign('lbwsf_if', $i_if); 
        $this->assign('lbwsf', $category);

        //获得帮助明细列表打印
        $gdlist['sk_lbw_vipid'] = $uid;
        $gdlist['sf_jy_status']=array('neq',8);
        $gdlist['sf_jy_status']=array('neq',2);
        $categorygd = D('UserPipeioder')->where($gdlist)->limit(50)->select();
        $t_if=count($categorygd);
        $this->assign('lbwgd', $categorygd);
        $this->display();

    }
    //激活码
    public function Jihuoma(){  
        $uid = $this->is_login();
        $abc=I('post.jihuoma');
        $uid_cx['id']=$uid;
        $username=D('User')->where($uid_cx)->getField('username');
        $if_jh=D('User')->where($uid_cx)->getField('jh_yq_ma');
        if($if_jh == 1){
            $this->error('您已激活请不要重复激活！', U('User/center'));
        }

       // $abc='JHF501403319826534';
        $data['jihuoma'] = $abc;
        $data['jihuo_zhuangtai']=array('NEQ',1);
        $b=D('Jihuoma')->where($data)->getField('jihuoma');
        if($b==$abc){
            $datatwo['jihuo_zhuangtai']=1;
            $datatwo['username']=$username;
            D('Jihuoma')->where($data)->save($datatwo);
            $datathree['jh_yq_ma']=1;
            $datathree['jihuo_xlh']=$abc;
            D('User')->where('id='.$uid)->save($datathree);
            $this->success('恭喜您激活成功', U('User/center'));
        }else{
            $this->error('您输入的激活码错误或已使用请重新输入！', U('User/center'));
        }
    }

    /**
     * 用户修改信息
     *
     */
    public function profile()
    {
        if (IS_POST) {
            $user_object = D('User');
            $_POST['id'] = $this->is_login();
            $result = $user_object->update($_POST);
            if ($result) {
                $this->success('信息修改成功');
            } else {
                $this->error($user_object->getError());
            }
        } else {
            $user_object = D('User');
            $user_info = $user_object->find($this->is_login());

            //使用FormBuilder快速建立表单页面。
            $builder = new \Common\Builder\FormBuilder();
            $builder->setMetaTitle('修改' . $user_info['username'] . '的信息')//设置页面标题
            ->setPostUrl(U(''))//设置表单提交地址
            ->addFormItem('username', 'text', '用户名', '')
                ->addFormItem('avatar', 'picture', '头像', '')
                ->addFormItem('sex', 'radio', '性别', '', $user_object->user_sex())
                ->addFormItem('age', 'num', '年龄', '')
                ->addFormItem('birthday', 'date', '生日', '生日')
                ->addFormItem('summary', 'text', '签名', '一句话介绍')
                ->setFormData($user_info)
                ->setTemplate('_Builder/formbuilder_user')
                ->display();
        }
    }

    /**
     * 登陆
     *
     */
    public function login()
    {
        if (IS_POST) {
            $username = I('username');
            $password = I('password');
            if (!$username) {
                $this->error('请输入账号！');
            }
            if (!$password) {
                $this->error('请输入密码！');
            }
            if (!$this->check_verify(I('post.verify'))) {
                $this->error('验证码输入错误！');
            }
            $user_object = D('User');
            $uid = $user_object->login($username, $password);
            if (0 < $uid) {
                $this->success('登录成功！', Cookie('__forward__') ? C('HOME_CENTER_LBW') : C('HOME_PAGE'));
            } else {
                $this->error($user_object->getError());
            }
        } else {
            if (is_login()) {
                $this->error("您已登陆系统", Cookie('__forward__') ? C('HOME_CENTER_LBW') : C('HOME_PAGE'));
            }
            $this->meta_title = '用户登录';
            $this->display();
        }
    }

    public function loginbt()
    {
        if (IS_POST) {
            $username = I('username');
            $password = I('password');
            if (!$username) {
                $this->error('请输入账号！');
            }
            if (!$password) {
                $this->error('请输入密码！');
            }
            if (!$this->check_verify(I('post.verify'))) {
                $this->error('验证码输入错误！');
            }
            $user_object = D('User');
            $uid = $user_object->login($username, $password);
            if (0 < $uid) {
                $this->success('登录成功！', Cookie('__forward__') ? C('HOME_CENTER_LBW') : C('HOME_PAGE'));
            } else {
                $this->error($user_object->getError());
            }
        } else {
            if (is_login()) {
                $this->error("您已登陆系统", Cookie('__forward__') ? C('HOME_CENTER_LBW') : C('HOME_PAGE'));
            }
            $this->meta_title = '用户登录';
            $this->display();
        }
    }



    /**
     * 注销
     *
     */
    public function logout()
    {
        session('user_auth', null);
        session('user_auth_sign', null);
        $this->success('退出成功！', Cookie('__forward__') ?: C('HOME_PAGE'));
    }

    /**
     * 用户注册
     *
     */
    public function register()
    {
        if (IS_POST) {
            if (!C('TOGGLE_USER_REGISTER')) {
                $this->error('注册已关闭！');
            }
        //    $reg_type = I('post.reg_type');

          //  if (!in_array($reg_type, C('ALLOW_REG_TYPE'))) {
            //    $this->error('该注册方式已关闭，请选择其它方式注册！');
           // }
            //switch ($reg_type) {
            //    case 'username': //用户名注册
                  //  $username = I('post.username');
                    //图片验证码校验
            //        if (!$this->check_verify(I('post.verify'))) {
               //         $this->error('验证码输入错误！');
              //      }
              //      break;
           ///     case 'email': //邮箱注册
            //        $username = I('post.email');
            //        $_POST['username'] = 'U' . NOW_TIME;
                  //验证码严格加盐加密验证
          //          if (user_md5(I('post.verify'), $username) !== session('reg_verify')) {
              //          $this->error('验证码错误！');
            //        }
                //    break;
                //case 'mobile': //手机号注册
                   $usernamet = I('post.mobile');
                   //$_POST['username'] = 'U' . NOW_TIME;
                   // 验证码严格加盐加密验证
                  if (user_md5(I('post.verify'), $usernamet) !== session('reg_verify')) {
                       $this->error('验证码错误！');
                   }
                 //   break;
            $username = I('post.username');
            $password = I('post.password');
            $user_object = D('User');
            $data = $user_object->create();
            if ($data) {
                $id = $user_object->add();
                if ($id) {
                    session('reg_verify', null);
                    $uid = $user_object->login($username, $password);
                    $parentId = I('post.lbw_tuijianren');
                    $paren['id'] = $uid;
                    $paren['parentId'] = $parentId;
                    $paren['name'] = $username;
                    D('UserTuiguang')->add($paren);
                    //录入推广图池
                    //下面查找所有上级id
                    $dataabc['id'] = $parentId;
                    $tianjia['tuijianrenku'] = array('like',array('%,' . $parentId . ',%','%,'.$parentId.'%'),'OR');
                    $lbw_a = D('User')->where($tianjia)->select();
                    $lbw_b = count($lbw_a);
                    $ac = array();
                    $ab = array();
                    for ($i = 0; $i < $lbw_b; $i++) {
                        $ac[] = $lbw_a[$i]['id'];
                        $ab[] = $lbw_a[$i]['tuijianrenku'];
                    }
                    $cc = count($ac);
                    //下面循环录入
                    for ($i = 0; $i < $cc; $i++) {
                        $tianjiab['id'] = $ac[$i];
                        $tianjiac['tuijianrenku'] = $ab[$i] . ',' . $uid;
                        D('User')->where($tianjiab)->save($tianjiac);
                    }
                    //写入直属上级推荐池
                    $lbw_prd = D('User')->where($dataabc)->getField('tuijianrenku');
                    $tianjiae['tuijianrenku'] = $lbw_prd . ',' . $uid;
                    D('User')->where($dataabc)->save($tianjiae);

                    //计入user表推荐人数
                    $tuijian_pp_id['id'] = $parentId; //构造直推id人的数据查询
                    //拿到直推人的推荐总人数
                    $lbw_zhitui_js = D('User')->where($tuijian_pp_id)->getField('lbw_zhitui');
                    //即将更新直推人的总人数
                    $tuijian_pp_zs['lbw_zhitui'] = $lbw_zhitui_js + 1;
                    D('User')->where($tuijian_pp_id)->save($tuijian_pp_zs);
                    $uid = $user_object->login($username, $password);
                    session('user_auth', null);
                    session('user_auth_sign', null);
                    $this->success('注册成功', U('User/center'));
                } else {
                    $this->error('注册失败');
                }
            } else {
                $this->error($user_object->getError());
            }
        } else {
            if (is_login()) {
                $this->error("您已登陆系统", Cookie('__forward__') ? C('HOME_CENTER_LBW') : C('HOME_PAGE'));
            }
            $this->meta_title = '用户注册';
            $this->display();
        }
    }
    /**用户注册用户内使用**/
    /**
     * 用户注册
     *
     */
    public function registertwo()
    {
        if (IS_POST) {
            if (!C('TOGGLE_USER_REGISTER')) {
                $this->error('注册已关闭！');
            }
            //    $reg_type = I('post.reg_type');

            //  if (!in_array($reg_type, C('ALLOW_REG_TYPE'))) {
            //    $this->error('该注册方式已关闭，请选择其它方式注册！');
            // }
            //switch ($reg_type) {
            //    case 'username': //用户名注册
            //  $username = I('post.username');
            //图片验证码校验
            //        if (!$this->check_verify(I('post.verify'))) {
            //         $this->error('验证码输入错误！');
            //      }
            //      break;
            ///     case 'email': //邮箱注册
            //        $username = I('post.email');
            //        $_POST['username'] = 'U' . NOW_TIME;
            //验证码严格加盐加密验证
            //          if (user_md5(I('post.verify'), $username) !== session('reg_verify')) {
            //          $this->error('验证码错误！');
            //        }
            //    break;
            //case 'mobile': //手机号注册
            $usernamet = I('post.mobile');
            $_POST['username'] = 'U' . NOW_TIME;
            //验证码严格加盐加密验证
            if (user_md5(I('post.verify'), $usernamet) !== session('reg_verify')) {
                $this->error('验证码错误！');
           }
            //   break;
            $username = I('post.username');
            $password = I('post.password');
            $user_object = D('User');
            $data = $user_object->create();
            if ($data) {
                $id = $user_object->add();
                if ($id) {
                    session('reg_verify', null);
                    $uid = $user_object->login($username, $password);
                    $parentId = I('post.lbw_tuijianren');
                    $paren['id'] = $uid;
                    $paren['parentId'] = $parentId;
                    $paren['name'] = $username;
                    D('UserTuiguang')->add($paren);
                    //录入推广图池
                    //下面查找所有上级id
                    $dataabc['id'] = $parentId;
                    $tianjia['tuijianrenku'] = array('like',array('%,' . $parentId . ',%','%,'.$parentId.'%'),'OR');
                    $lbw_a = D('User')->where($tianjia)->select();
                    $lbw_b = count($lbw_a);
                    $ac = array();
                    $ab = array();
                    for ($i = 0; $i < $lbw_b; $i++) {
                        $ac[] = $lbw_a[$i]['id'];
                        $ab[] = $lbw_a[$i]['tuijianrenku'];
                    }
                    $cc = count($ac);
                    //下面循环录入
                    for ($i = 0; $i < $cc; $i++) {
                        $tianjiab['id'] = $ac[$i];
                        $tianjiac['tuijianrenku'] = $ab[$i] . ',' . $uid;
                        D('User')->where($tianjiab)->save($tianjiac);
                    }
                    //写入直属上级推荐池
                    $lbw_prd = D('User')->where($dataabc)->getField('tuijianrenku');
                    $tianjiae['tuijianrenku'] = $lbw_prd . ',' . $uid;
                    D('User')->where($dataabc)->save($tianjiae);

                    //计入user表推荐人数
                    $tuijian_pp_id['id'] = $parentId; //构造直推id人的数据查询
                    //拿到直推人的推荐总人数
                    $lbw_zhitui_js = D('User')->where($tuijian_pp_id)->getField('lbw_zhitui');
                    //即将更新直推人的总人数
                    $tuijian_pp_zs['lbw_zhitui'] = $lbw_zhitui_js + 1;
                    D('User')->where($tuijian_pp_id)->save($tuijian_pp_zs);
                    session('user_auth', null);
                    session('user_auth_sign', null);
                    $username = I('post.usernametwo');
                    $password = I('post.passwordtwo');
                    $uid = $user_object->loginbt($username, $password);
                    $this->success('注册成功', U('User/center'));
                } else {
                    $this->error('注册失败');
                }
            } else {
                $this->error($user_object->getError());
            }
        } else {
            if (is_login()) {
                $this->error("您已登陆系统", Cookie('__forward__') ? C('HOME_CENTER_LBW') : C('HOME_PAGE'));
            }
            $this->meta_title = '用户注册';
            $this->display();
        }
    }

    //一键登陆
    public function vipLogin(){
        $key=$_GET['key'];
        if($key=='ilikemilke'){
        $username=$_GET['username'];
        $user_object = D('User');
        $where['username']=$username;
        $user =$user_object->where($where)->find();
        //记录登录SESSION和COOKIES
        $auth = array(
            'uid'             => $user['id'],
            'username'        => $user['username'],
            'avatar'          => $user['avatar'],
            'last_login_time' => $user['last_login_time'],
            'last_login_ip'   => get_client_ip(1),
        );
        session('user_auth', $auth);
        //数据类型检测
        if(!is_array($auth)){
            $auth = (array)$auth;
        }
        ksort($auth); //排序
        $code = http_build_query($auth); //url编码并生成query字符串
        $sign = sha1($code); //生成签名
        session('user_auth_sign',$sign);
        $this->success('登录成功！', Cookie('__forward__') ? C('HOME_CENTER_LBW') : C('HOME_PAGE'));
        }else{
            $this->error('错误您无权访问 ！');
        }
    }


    //测试

    public function oobob()
    {
      $this->display();
      
    }

    /*
   public function adad()
   {
       $parentId = 10;
       $dataabc['id']=$parentId;
       $tianjia['tuijianrenku']=array('like','%'.$parentId.'%');
       $lbw_a=D('User')->where($tianjia)->select();
       $lbw_prd=D('User')->where($dataabc)->getField('tuijianrenku');
       $tianjiae['tuijianrenku']=$lbw_prd.','.;
       D('User')->where($dataabc)->save($tianjiae);
       echo header("Content-type: text/html; charset=utf-8");
       echo var_dump($lbw_prd);
   }
   * /
     /*   $tianjia['tuijianrenku']=array('like','%'.$parentId.'%');
        $data['tuijianrenku']=','."99";
        $lbw_a=D('User')->where($tianjia)->select();
        $lbw_b=count($lbw_a);
        for($i=0;$i<$b;$i++){
            $ac[]=$a[$i]['id'];
            $ab[]=$a[$i]['tuijianrenku'];
        }
        $cc=count($ac);

        for($i=0;$i<$cc;$i++){
            $tianjiab['id']=$ac[$i];
            $tianjiac['tuijianrenku']=$ab[$i].','."99";
            D('User')->where($tianjiab)->save($tianjiac);
        }

       $tianjia['id']=$parentId;
       $tianjia['tuijianrenku']=array('like','%'.$parentId.'%');
       $lbw_a=D('User')->where($tianjia)->select();
       $lbw_b=count($lbw_a);
       $ac=array();
       $ab=array();
       for($i=0;$i<$lbw_b;$i++){
           $ac[]=$lbw_a[$i]['id'];
           $ab[]=$lbw_a[$i]['tuijianrenku'];
       }
       $cc=($ac);
       //下面循环录入
      for($i=0;$i<$cc;$i++){
    //       $tianjiab['id']=$ac[$i];$tianjiac['tuijianrenku']=$ab[$i].','.$uid;
    //       D('User')->where($tianjiab)->save($tianjiac);
     //  }
       // for($i=0;$){
      //  $tianjiab['id']=$ab[$i];
      //  $data['tuijianrenku']=$ab[$b].','.'99';
     //   D('User')->where($tianjiab)->save($data);
     //  }
    echo ($ac);
    }
*/


    /**
     * 密码重置主页
     *
     */
    public function resetPassword()
    {

            $this->meta_title = '密码重置';
            $uid = $this->is_login();
            $user_info = D('User')->where($con)->find($uid);
            $this->assign('meta_title', '获得帮助列表');
            $this->assign('user_id', $user_info['username']);
            $this->assign('user_username', $user_info['id']);
            $obq = D('User')->where('id=' . $uid)->select();
            $tjr = D('User')->where('id=' . $uid)->getField('lbw_tuijianren');
            $tjr_mobile = D('User')->where('id=' . $tjr)->getField('mobile');
            $usename_tjr=D('User')->where('id=' . $tjr)->getField('username');
            $usename_name=D('User')->where('id=' . $tjr)->getField('realname');
            $this->assign('lbwlistt', $obq);
            $this->assign('tjrmb', $tjr_mobile);
            $this->assign('user_time', $user_info['ctime']);
             $this->assign('user_jtmoney', $user_info['user_jt_money']);
            $this->assign('user_jt_ye',$user_info['user_jt_money']);
             $this->assign('user_dt_ye',$user_info['user_dt_money']);
             $this->assign('user_pda', $user_info['lbw_paidancount']);
            $this->assign('usename_name', $usename_name);
            $this->assign('usename_tjr', $usename_tjr);
        
            $this->display();

    }
    //一级密码重置功能
    public function restOnePwd(){
        $username = I('post.mobile');
        $condition['mobile'] = I('post.mobile');
        if (user_md5(I('post.verify'), $username) !== session('reg_verify')) {
            $this->error('验证码错误！');
        }
        $user_object = D('User');
        $data = $user_object->create($_POST, 5);
        if(!$data){
            $this->error($user_object->getError());
        }
        $result = $user_object->where($condition)->setField('password', $data['password']); //重置密码
        $uid = $user_object->login($username, I('post.password')); //自动登录
        if($uid){
            $this->success('密码重置成功', C('HOME_PAGE'));
        }else{
            $this->error('密码重置失败');
        }
    }

    //二级密码重置功能
    public function restTwoPwd(){
        $username = I('post.mobiletwo');
        $condition['mobile'] = I('post.mobiletwo');
        if (user_md5(I('post.verify'), $username) !== session('reg_verify')) {
            $this->error('验证码错误！');
        }
        $user_object = D('User');
        $data = $user_object->create($_POST, 5);
        if(!$data){
            $this->error($user_object->getError());
        }
        $result = $user_object->where($condition)->setField('lbw_twopwd', $data['lbw_twopwd']); //重置密码
        if($result){
            $this->success('二级密码重置成功', C('HOME_PAGE'));
        }else{
            $this->error('二级密码重置失败');
        }
    }


    /**
     * 图片验证码生成，用于登录和注册
     *
     */
    public function verify($vid = 1)
    {
        $config =    array(
            'fontSize'    =>    50,    // 验证码字体大小
            'length'      =>    4,     // 验证码位数
            'useNoise'    =>    false, // 关闭验证码杂点
        );
        $verify = new \Think\Verify($config);
        $verify->codeSet = '0123456789';
        $verify->entry($vid);
    }

    /**
     * 检测验证码
     * @param  integer $id 验证码ID
     * @return boolean 检测结果
     */
    function check_verify($code, $vid = 1)
    {
        $verify = new \Think\Verify();
        return $verify->check($code, $vid);
    }

    /**
     * 邮箱验证码，用于注册
     *
     */
    public function sendMailVerify()
    {
        $user_object = D('User');
        $result = $user_object->create($_POST, 5); //调用自动验证
        if (!$result) {
            $this->error($user_object->getError());
        }

        //生成验证码
        $reg_verify = \Org\Util\String::randString(6, 1);
        session('reg_verify', user_md5($reg_verify, I('post.email')));

        //构造邮件数据
        $mail_data['receiver'] = I('post.email');
        $mail_data['subject'] = '邮箱验证';
        $mail_data['content'] = '少侠/女侠好：<br>听闻您正使用该邮箱' . I('post.email') . '【注册/修改密码】，请在验证码输入框中输入：
        <span style="color:red;font-weight:bold;">' . $reg_verify . '</span>，以完成操作。<br>
        注意：此操作可能会修改您的密码、登录邮箱或绑定手机。如非本人操作，请及时登录并修改
        密码以保证帐户安全 （工作人员不会向您索取此验证码，请勿泄漏！)';

        //发送邮件
        if (send_mail($mail_data)) {
            $this->success('发送成功，请登陆邮箱查收！');
        } else {
            $this->error('发送失败！');
        }
    }

    /**
     * 短信验证码，用于注册
     *
     */
    public function sendMobileVerify()
    {
        $user_object = D('User');
        $result = $user_object->create($_POST, 5); //调用自动验证
        if (!$result) {
            $this->error($user_object->getError());
        }

        //生成验证码
        $reg_verify = \Org\Util\String::randString(6, 1);
        session('reg_verify', user_md5($reg_verify, I('post.mobile')));

        //构造短信数据
        $msg_data = I('post.mobile');
        $msg_datatwo = '短信验证码：' . $reg_verify;
        $fanhui=send_mobile_message($msg_data,$msg_datatwo);
        function send_mobile_message($receiver, $body){
            $statusStr = array(
                "0" => "短信发送成功",
                "-1" => "参数不全",
                "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
                "30" => "密码错误",
                "40" => "账号不存在",
                "41" => "余额不足",
                "42" => "帐户已过期",
                "43" => "IP地址限制",
                "50" => "内容含有敏感词"
            );
            $smsapi = "http://api.smsbao.com/";
            $user = "916137925"; //短信平台帐号
            $pass = md5("songjie19920607"); //短信平台密码
            $content="您的短信验证码为: ".$body;//要发送的短信内容
            $phone = $receiver;//要发送短信的手机号码
            $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
            $result =file_get_contents($sendurl) ;
            return $statusStr[$result];
        }
        $this->error($fanhui);
       // switch ($fanhui){

        //}
       // if (send_mobile_message($msg_data)) {
      //      $this->success('发送成功，请查收！');
       // } else {
       //     $this->error('发送失败！');
       // }
    }

    //短信重置一级密码
    public function restMobileVerify(){
        //生成验证码
        $reg_verify = \Org\Util\String::randString(6, 1);
        session('reg_verify', user_md5($reg_verify, I('post.mobile')));

        //构造短信数据
        $msg_data = I('post.mobile');
        $msg_datatwo = '短信验证码：' . $reg_verify;
        $fanhui=send_mobile_message($msg_data,$msg_datatwo);
        function send_mobile_message($receiver, $body){
            $statusStr = array(
                "0" => "短信发送成功",
                "-1" => "参数不全",
                "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
                "30" => "密码错误",
                "40" => "账号不存在",
                "41" => "余额不足",
                "42" => "帐户已过期",
                "43" => "IP地址限制",
                "50" => "内容含有敏感词"
            );
            $smsapi = "http://api.smsbao.com/";
            $user = "916137925"; //短信平台帐号
            $pass = md5("songjie19920607"); //短信平台密码
            $content="您的短信验证码为: ".$body;//要发送的短信内容
            $phone = $receiver;//要发送短信的手机号码
            $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
            $result =file_get_contents($sendurl) ;
            return $statusStr[$result];
        }
        $this->error($fanhui);
    }
    /**
     * 用户推广链接生成
     *
     *
     * public function craetSpread()
     * {
     * $uid = I('get.uid');
     * if (!$uid) {
     * $uid = $this->is_login();
     * }
     * $user_info = D('User')->where($con)->find($uid);
     * if ($user_info['status'] !== '1') {
     * $this->error('该用户不存在或已禁用');
     * }
     *
     * $this->assign('qc', C('HOME_PAGE'));
     * $this->assign('meta_title', $user_info['username'] . '推广链接');
     * $this->display();
     * }
     * */
    /*
     * 身份证验证
     */
    public function idcard()
    {
        $lbw_idcard = $_POST['idcard'];
        $curl = curl_init();
        $lbwurl = "http://a.apix.cn/tongyu/idcardinfo/id?id=" . $lbw_idcard;
        curl_setopt_array($curl, array(
            CURLOPT_URL => $lbwurl,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_HTTPHEADER => array(
                "accept: application/json",
                "apix-key: 052a3e4cb3004caf438a2e5ba4e04c74",
                "content-type: application/json"
            ),
        ));
        $response = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);
        if ($err) {
            echo $err;
        } else {
            echo $response;
        }
    }

    //调试器
    public function aaa()
    {
        $uid = $this->is_login();
        date_default_timezone_set('Asia/Shanghai');//此句用于消除时间差
        $nowtime = date("Y-m-d H:i:s");
        $abb = date('Y-m-d H:i:s', strtotime("$nowtime-30 day"));
        $map['lbw_vipid'] = $uid;
        $map['creattime'] = array('EGT', $abb);
        $lbw_abc = D("UserTemppipeiorder")->where($map)->select();
        echo header("Content-Type:text/html;charset=utf-8");
        if (count($lbw_abc) >= 4) {
            echo '本月排单次数已满';
        } else {
            $abc = date('Y-m-d H:i:s', strtotime("$nowtime-30 day"));
            $mop['lbw_vipid'] = $uid;
            $mop['creattime'] = array('EGT', $abc);
            $mop['jiaoyi_zt'] = 0;
            $lbw_adb = D("UserTemppipeiorder")->where($mop)->select();
            $li = count($lbw_adb);
            for ($i = 0; $i < $li; $i++) {
                $a = $lbw_adb[$i]['lbw_order_pipei'];

            }
        }

    }

    /*
     * 提供帮助控制器
     */
    public function getHelp()
    {
        $uid = $this->is_login();
        //生成订单号

        $jihuoma['id']=$uid;
        $jihuomazt=D('User')->where($jihuoma)->getField('jh_yq_ma');
        if($jihuomazt==0){
            $this->error('您的账户尚未激活请先激活!', U('User/center'));
        }

        $lbw_twopwd = I('post.lbw_twopwd', '', 'user_md5');
        $lbwif_money = I('post.amount');
        $datacig_zd['name'] = "LBW_TGBZJE_ZD";    //获取提供帮助最低金额设置
        $lbw_config_zd_money = D('SystemConfig')->where($datacig_zd)->getField('value');
        $datacig_zg['name'] = "LBW_TGBZJE_ZG";  //获取提供帮助最高金额设置
        $lbw_config_zg_money = D('SystemConfig')->where($datacig_zg)->getField('value');
        $datacig_bs['name'] = "LBW_TGBZJE_BS"; //获取倍数设置
        $lbw_config_bs = D('SystemConfig')->where($datacig_bs)->getField('value');
        $datacig_bfc['name'] = "LBW_PDDDSJ_SJ"; //获取排队等待时间设置
        $lbw_config_bfc = D('SystemConfig')->where($datacig_bfc)->getField('value');
        $newtime=date('Y-m-d H:i:s', strtotime("+" . $lbw_config_bfc . " minute", time()));//生成倒数时间
        /*准备开始检测每月排单数量
        *每月排单数量记录
        */
        $lbw_erjimima['id'] = $uid;
        $twopdw = D('User')->where($lbw_erjimima)->getField('lbw_twopwd');
        if ($twopdw != $lbw_twopwd) {
            $this->error('二级密码输入错误请重新输入!', U('User/center'));
        }

        if ($lbw_config_zd_money <= $lbwif_money and $lbw_config_zg_money >= $lbwif_money) {
            if ($lbwif_money % $lbw_config_bs == 0) {
                $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
                $orderSn = "fk" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
                //The end
                //找出姓名
                $Username = M("User");
                $RealName = $Username->where('id=' . $uid)->getField('realname');
                $mymobile = $Username->where('id=' . $uid)->getField('mobile');
                $mybank_name = $Username->where('id=' . $uid)->getField('lbw_bankname');
                $mybank_number = $Username->where('id=' . $uid)->getField('lbw_banknumber');
                $myalipay = $Username->where('id=' . $uid)->getField('lbw_alipay');
                $mytjr_id = $Username->where('id=' . $uid)->getField('lbw_tuijianren');
                $mytjr_mobile = $Username->where('id=' . $mytjr_id)->getField('mobile');
                $mytjr_first = $Username->where('id=' . $mytjr_id)->getField('realname');
                $mytjr_username=$Username->where('id=' . $mytjr_id)->getField('username');
                $paidan_total = $Username->where('id=' . $uid)->getField('lbw_paidancount'); //拿出排单总数
                $user_name = $Username->where('id=' . $uid)->getField('username'); //拿出用户名
                $data_gx_zt['lbw_paidancount'] = $paidan_total + 1;
                $data_gx_zt['last_dk_time']=date("Y-m-d H:i:s");

                $Username->where('id=' . $uid)->save($data_gx_zt);
                //支付方法
                $payMethod = array();
                $payMethod[0] = I('post.zffs1');
                $payMethod[1] = I('post.zffs2');
                $payMethod[2] = I('post.zffs3');
                // $creatTime=strtotime(date("Y-m-d H:i:s")); //生成创建时间戳
                $creatTime = date("Y-m-d H:i:s");  //生成创建时间戳
                $User = M("UserTemppipeiorder");
                $data['lbw_order_pipei'] = $orderSn;                        //匹配订单号
                $data['lbw_vipid'] = $uid;                          //匹配会员id
                $data['creattime'] = $creatTime;                               //创建时间
                $data['creattimetwo']=strtotime($newtime);  //系统冻结检测时间
                $data['money_total'] = I('post.amount');                 //匹配金额
                $data['yipipei_money'] = "0";                          //已匹配金额
                $data['yijy_moeny'] = "0";                              //已交易金额
                $data['peiduifs'] = $payMethod[0] . $payMethod[1] . $payMethod[2];                    //支付方法
                $data['peidui_cishu'] = "0";                //匹配次数
                $data['fk_name'] = $RealName;
                $data['fk_my_mobile'] = $mymobile;
                $data['bank_name'] = $mybank_name;
                $data['bank_number'] = $mybank_number;
                $data['alipay'] = $myalipay;
                $data['fk_sj_mobile'] = $mytjr_mobile;
                $data['username'] = $user_name; //存入用户名
                $data['total_forever'] = $lbwif_money; //存入恒定展示额
                $data['tuijianrenxm']=$mytjr_first;
                $data['tjr_username']=$mytjr_username; //存入推荐人用户名
                $User->data($data)->add();
                $this->success('提交成功', U('User/center'));
            } else {
                $this->error('错误!金额必须为整数且必须为' . $lbw_config_bs . "的倍数", U('User/center'));
            }
        } else {
            $this->error('错误!金额不得超出:' . $lbw_config_zg_money . '或者不得低于:' . $lbw_config_zd_money, U('User/center'));
        }

    }

    /*
     * 获得帮助生成控制器
     */
    public function LbwProvide()
    {
        $uid = $this->is_login();

        $jihuoma['id']=$uid;
        $jihuomazt=D('User')->where($jihuoma)->getField('jh_yq_ma');
        if($jihuomazt==0){
            $this->error('您的账户尚未激活请先激活!', U('User/center'));
        }


        $lbw_twopwd = trim(I('post.lbw_twopwd', '', 'user_md5'));
        $lbwif_money = trim(I('post.amount'));
        $lbwif_type=trim(I('post.qianbao'));
    if($lbwif_type==1){
            //静态钱包提现
        $datacig_zd['name'] = "LBW_HDBZ_ZD";    //获取提现最低金额设置
        $lbw_config_zd_money = D('SystemConfig')->where($datacig_zd)->getField('value');
        $datacig_zg['name'] = "LBW_HDBZ_ZG";  //获取提现最高金额设置
        $lbw_config_zg_money = D('SystemConfig')->where($datacig_zg)->getField('value');
        $datacig_bs['name'] = "LBW_TGBZJE_BS"; //获取倍数设置
        $lbw_config_bs = D('SystemConfig')->where($datacig_bs)->getField('value');

        $lbw_erjimima['id'] = $uid;
        $twopdw = D('User')->where($lbw_erjimima)->getField('lbw_twopwd');
        $user_zh_yue = D('User')->where($lbw_erjimima)->getField('user_jt_money');
        $user_jt_yue_dj = D('User')->where($lbw_erjimima)->getField('user_jt_money_no');
        $txzt_sd_if=D('User')->where($lbw_erjimima)->getField('tixian_sd');
        $data_cx_tx_zt['lbw_vipid']=$uid;
        $ktx_zt= D('UserTemppipeiorder')->where($data_cx_tx_zt)->getField('ketixian_zt');
        if($ktx_zt == 1){
            $this->error('您的交易正在冻结期请过后再试!',U('User/center'));
        }
        if($txzt_sd_if != 0){
            $this->error('您已被禁止提现!',U('User/center'));
        }
        if ($twopdw != $lbw_twopwd) {
            $this->error('二级密码输入错误请重新输入!', U('User/center'));
        }
        if ($lbwif_money > $user_zh_yue) {
            $this->error('请输入正确符合余额的金额!', U('User/center'));
        }

        if ($lbw_config_zd_money <= $lbwif_money and $lbw_config_zg_money >= $lbwif_money) {

            if ($lbwif_money % $lbw_config_bs == 0) {

                $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
                $orderSn = "sk" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
                //The end
                //找出姓名
                $Username = M("User");
                $RealName = $Username->where('id=' . $uid)->getField('realname');
                $mymobile = $Username->where('id=' . $uid)->getField('mobile');
                $mybank_name = $Username->where('id=' . $uid)->getField('lbw_bankname');
                $mybank_number = $Username->where('id=' . $uid)->getField('lbw_banknumber');
                $myalipay = $Username->where('id=' . $uid)->getField('lbw_alipay');
                $mytjr_id = $Username->where('id=' . $uid)->getField('lbw_tuijianren');
                $mytjr_mobile = $Username->where('id=' . $mytjr_id)->getField('mobile');
                $mytjr_first = $Username->where('id=' . $mytjr_id)->getField('realname');
                $tjr_username = $Username->where('id=' . $mytjr_id)->getField('username');
                $user_name = $Username->where('id=' . $uid)->getField('username'); //获取用户名
                $user_zh_yue = $user_zh_yue - $lbwif_money;
                $user_my_yue_sy['user_jt_money'] = $user_zh_yue; //剩余余额
                $user_my_yue_sy['user_jt_money_no'] = $user_jt_yue_dj + $lbwif_money; //冻结余额
                $Username->where('id=' . $uid)->save($user_my_yue_sy); //存入数据库
                //支付方式
                $payMethod = array();
                $payMethod[0] = I('post.zffs1');
                $payMethod[1] = I('post.zffs2');
                $payMethod[2] = I('post.zffs3');
                // $creatTime=strtotime(date("Y-m-d H:i:s")); //生成创建时间戳
                $creatTime = date("Y-m-d H:i:s");  //生成创建时间戳
                $User = M("UserTempskorder");
                $data['lbw_order_sk_id'] = $orderSn;                        //匹配订单号
                $data['lbw_vipid'] = $uid;                          //匹配会员id
                $data['creattime'] = $creatTime;                               //创建时间
                $data['money_total'] = I('post.amount');                 //匹配金额
                $data['yipipei_money'] = "0";                          //已匹配金额
                $data['yijy_moeny'] = "0";                              //已交易金额
                $data['peiduifs'] = $payMethod[0] . $payMethod[1] . $payMethod[2];                    //支付方法
                $data['shoukuan_cishu'] = "0";                //匹配次数
                $data['sk_name'] = $RealName;
                $data['sk_my_mobile'] = $mymobile;
                $data['bank_name'] = $mybank_name;
                $data['bank_number'] = $mybank_number;
                $data['alipay'] = $myalipay;
                $data['sk_sj_mobile'] = $mytjr_mobile;
                $data['username']=$user_name; //新增用户名存入
                $data['total_sk']=$lbwif_money; //收款恒定金额
                $data['tuijianrenxinm']=$mytjr_first;
                $data['tjr_username']=$tjr_username;  //存入推荐人用户名
                $User->data($data)->add();

                $data_cx_tx_zt['lbw_vipid']=$uid;
                $data_up_tx['ketixian_zt']=3;
                D('UserTemppipeiorder')->where($data_cx_tx_zt)->save($data_up_tx);
                $this->success('提交成功', U('User/center'));
            } else {
                $this->error('错误!金额必须为整数且必须为' . $lbw_config_bs . "的倍数", U('User/center'));
            }
        } else {
            $this->error('错误!金额不得超出:' . $lbw_config_zg_money . '或者不得低于:' . $lbw_config_zd_money, U('User/center'));
        }
    }else{
            /*
             * 动态钱包提现功能
             */
            $datadtcig_zd['name'] = "LBW_DTQBTX_ZD";    //获取动态提现最低金额设置
            $lbw_config_dt_zd_money = D('SystemConfig')->where($datadtcig_zd)->getField('value');
            $datadtcig_zg['name'] = "LBW_DTQBZGTX_SZ";  //获取动态提现最高金额设置
            $lbw_config_dt_zg_money = D('SystemConfig')->where($datadtcig_zg)->getField('value');
            $datadtcig_bs['name'] = "LBW_DTQBMR_TXCS"; //获取每日限制次数设置
            $lbw_config_dt_bs = D('SystemConfig')->where($datadtcig_bs)->getField('value');
            $datadtcig_bss['name'] = "LBW_TGBZJE_BS"; //获取倍数设置
            $lbw_dtconfig_bss = D('SystemConfig')->where($datadtcig_bss)->getField('value');
            //下面是用户数据查询
            $lbw_erjimima['id'] = $uid;
            $twopdw = D('User')->where($lbw_erjimima)->getField('lbw_twopwd');
            $user_zh_yue = D('User')->where($lbw_erjimima)->getField('user_dt_money');
            $user_jt_yue_dj = D('User')->where($lbw_erjimima)->getField('user_dt_money_no');
            $txzt_sd_if=D('User')->where($lbw_erjimima)->getField('tixian_sd');
            $user_name = D('User')->where($lbw_erjimima)->getField('username');  //获取用户名

            $cur_date = date('Y-m-d');  //获取当天时间
            $where_dt['creattime']=array('EGT',$cur_date); //查询条件
            $where_dt['lbw_vipid']=$uid;  //查询条件
            $where_dt['dt_qb']=1;
            $a=D('UserTempskorder')->where($where_dt)->select(); //查询今天是否有提现过
            $b=count($a);
            //开始判断是否有资格提现
            if($b>=$lbw_config_dt_bs){
                $this->error('错误!已超过当天最大提现次数', U('User/center'));
            }
             if ($twopdw != $lbw_twopwd) {
            $this->error('二级密码输入错误请重新输入!', U('User/center'));
             }
            if ($lbwif_money > $user_zh_yue) {
            $this->error('请输入正确符合余额的金额!', U('User/center'));
            }
            if($txzt_sd_if != 0){
            $this->error('您已被禁止提现!',U('User/center'));
             }
        //下面开始判断提现金额 区间
            if ($lbw_config_dt_zd_money <= $lbwif_money and $lbw_config_dt_zg_money >= $lbwif_money) {
                if ($lbwif_money % $lbw_dtconfig_bss == 0) { //判断必须为多少的倍数
                    //开始主体信息
                    $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
                    $orderSn = "sk" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
                    //The end
                    //找出姓名
                    $Username = M("User");
                    $RealName = $Username->where('id=' . $uid)->getField('realname');
                    $mymobile = $Username->where('id=' . $uid)->getField('mobile');
                    $mybank_name = $Username->where('id=' . $uid)->getField('lbw_bankname');
                    $mybank_number = $Username->where('id=' . $uid)->getField('lbw_banknumber');
                    $myalipay = $Username->where('id=' . $uid)->getField('lbw_alipay');
                    $mytjr_id = $Username->where('id=' . $uid)->getField('lbw_tuijianren');
                    $mytjr_first = $Username->where('id=' . $mytjr_id)->getField('realname');
                    $tjr_username = $Username->where('id=' . $mytjr_id)->getField('username');
                    $mytjr_mobile = $Username->where('id=' . $mytjr_id)->getField('mobile');
                    $user_zh_yue = $user_zh_yue - $lbwif_money;
                    $user_my_yue_sy['user_dt_money'] = $user_zh_yue; //剩余余额
                    $user_my_yue_sy['user_dt_money_no'] = $user_jt_yue_dj + $lbwif_money; //冻结余额
                    $Username->where('id=' . $uid)->save($user_my_yue_sy); //存入数据库
                    //支付方式
                    $payMethod = array();
                    $payMethod[0] = I('post.zffs1');
                    $payMethod[1] = I('post.zffs2');
                    $payMethod[2] = I('post.zffs3');
                    // $creatTime=strtotime(date("Y-m-d H:i:s")); //生成创建时间戳
                    $creatTime = date("Y-m-d H:i:s");  //生成创建时间戳
                    $User = M("UserTempskorder");
                    $data['lbw_order_sk_id'] = $orderSn;                        //匹配订单号
                    $data['lbw_vipid'] = $uid;                          //匹配会员id
                    $data['creattime'] = $creatTime;                               //创建时间
                    $data['money_total'] = trim(I('post.amount'));                 //匹配金额
                    $data['yipipei_money'] = "0";                          //已匹配金额
                    $data['yijy_moeny'] = "0";                              //已交易金额
                    $data['peiduifs'] = $payMethod[0] . $payMethod[1] . $payMethod[2];                    //支付方法
                    $data['shoukuan_cishu'] = "0";                //匹配次数
                    $data['sk_name'] = $RealName;
                    $data['sk_my_mobile'] = $mymobile;
                    $data['bank_name'] = $mybank_name;
                    $data['bank_number'] = $mybank_number;
                    $data['alipay'] = $myalipay;
                    $data['sk_sj_mobile'] = $mytjr_mobile;
                    $data['dt_qb']=1;
                    $data['username']=$user_name;
                    $data['tuijianrenxinm']=$mytjr_first;
                    $data['tjr_username']=$tjr_username;  //存入推荐人用户名
                    $User->data($data)->add();
                    $this->success('提交成功', U('User/center'));

                }else {
                    $this->error('错误!金额必须为整数且必须为' . $lbw_dtconfig_bss . "的倍数", U('User/center'));
                }
            }else{
                $this->error('错误!金额不得超出:' . $lbw_config_dt_zg_money . '或者不得低于:' . $lbw_config_dt_zd_money, U('User/center'));
            }

        }
    }

    /*
     * 付款匹配功能主体
     */
    public function makeOneMoneyPlan()
    {
        //创建数据模型
        $FKUser = M("UserTemppipeiorder");
        $SKUser = M("UserTempskorder");
        $datacig_bfb['name'] = "LBW_SCPIPEI_MONEY"; //获取倍数设置
        $lbw_config_bfb = D('SystemConfig')->where($datacig_bfb)->getField('value');
        //提供帮助匹配信息读取
        $data_new_cx['peidui_status']=array('eq',0);
        $data_new_cx['peidui_cishu']=array('eq',0);
        $data_new_cx['creattimetwo']=array('LT',time());
        $fk_sj = $FKUser->where($data_new_cx)->order('creattime')->limit(1)->select(); //拿最先匹配的一条数据
        $fk_yuanmoney = $fk_sj[0]["money_total"];//付款数据库直取金额
        $fk_money = $fk_yuanmoney; //* $lbw_config_bfb; //付款金额的参数
        $fk_vipid = $fk_sj[0]["lbw_vipid"];  //付款会员id
        $fk_dh = $fk_sj[0]["lbw_order_pipei"]; //付款匹配订单号
        $fk_fangfa = $fk_sj[0]["peiduifs"];   //付款匹配方法
        $fk_id = $fk_sj[0]["id"];           //匹配付款订单序号
        $fk_zhuangtai = $fk_sj[0]["peidui_status"]; //匹配状态
        $fk_cishu = $fk_sj[0]["peidui_cishu"];
        $fk_name = $fk_sj[0]['fk_name'];  //姓名
        $fk_bankNumber = $fk_sj[0]['bank_number'];
        $fk_bankName = $fk_sj[0]['bank_name'];
        $fk_alipay = $fk_sj[0]['alipay'];
        $fk_sj_mobile = $fk_sj[0]['fk_sj_mobile'];
        $fk_my_mobile = $fk_sj[0]['fk_my_mobile'];
        $fk_yipipei_my=$fk_sj[0]['yipipei_money']; //拿到已匹配金额数据
        $fk_username=$fk_sj[0]['username'];//拿到付款人用户名
        $fk_tuijianName=$fk_sj[0]['tuijianrenxm']; //打款推荐人姓名存入
        $fk_tuijianuserName=$fk_sj[0]['tjr_username']; //打款推荐人姓名存入
        $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '5'); //同会员获得帮助数据剔除
        //获得帮助匹配信息读取
        $sk_data['money_total'] = array('gt', 0); ///构造总金额不等于零的收款数据查询
        $sk_data['jiaoyi_zt'] = array('eq', 0); //构造订单状态为0的收款配对查询
        $sk_data['jiaoyi_zt'] = array('neq', 9); //等于9就是处罚过冻结的订单无法继续完成交易
        $sk_data['peidui_status'] = array('neq', 5); //构造不会匹配到自己提现订单的条件
        $sk_sj = $SKUser->where($sk_data)->order('creattime')->limit(1)->select();
        $sk_money = $sk_sj[0]["money_total"];  //收款金额
        $sk_vipid = $sk_sj[0]["lbw_vipid"];   //收款会员id
        $sk_dh = $sk_sj[0]["lbw_order_sk_id"]; //收款订单号
        $sk_fangfa = $sk_sj[0]["peiduifs"];   //收款支持方法
        $sk_id = $sk_sj[0]["id"]; //匹配收款订单序号
        $sk_zhuangtai = $sk_sj[0]["peidui_status"];  //收款匹配状态
        $sk_cishu = $sk_sj[0]["shoukuan_cishu"];
        $sk_name = $sk_sj[0]['sk_name'];
        $sk_bankNumber = $sk_sj[0]['bank_number'];
        $sk_bankName = $sk_sj[0]['bank_name'];
        $sk_alipay = $sk_sj[0]['alipay'];
        $sk_sj_mobile = $sk_sj[0]['sk_sj_mobile'];
        $sk_my_mobile = $sk_sj[0]['sk_my_mobile'];
        $sk_yipp_money = $sk_sj[0]['yipipei_money'];  //拿到已匹配金额数据
        $sk_username = $sk_sj[0]['username'];  //拿到收款人用户名
        $sk_tuijianName=$sk_sj[0]['tuijianrenxinm'];
        $sk_qianbao=$sk_sj[0]['dt_qb']; //拿到钱包类型
        $sk_tuijianuserName=$sk_sj[0]['tjr_username']; //收款推荐人姓名存入
        //比较两个订单金额大小
        if ($fk_money < $sk_money) {
            $SFUser = M("UserPipeioder"); //创建数据对象

            $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
            $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
            $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
            //双方匹配数据入库
            $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
            $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
            $data['dk_creattime'] = $creatTime;      //写入订单创建时间
            $data['dk_money_total'] = $fk_money; //付款的金额
            $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
            $data['dk_dakuan_status'] = '0'; //写入等待打款
            $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
            $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
            $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
            $data['sk_money_total'] = $sk_money; //收款金额
            $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
            $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
            $data['sf_jy_status'] = '0'; //写入双方交易状态
            $data['sk_name'] = $sk_name; //写入收款人姓名
            $data['fk_name'] = $fk_name;//写入付款人姓名
            $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
            $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
            $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
            $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
            $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
            $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
            $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
            $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
            $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
            $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
            $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
            $data['dk_username']=$fk_username; //写入打款人用户名
            $data['sk_username']=$sk_username; //写入收款人用户名
            $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
            $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
            $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
            $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
            $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
            $SFUser->data($data)->add(); //数据入库
            //更改双方临时匹配数据表状态
            //付款状态修改
            $data_lbw['money_total'] = '0';   //修改付款订单剩余匹配余额(付款小于收款，付款直接全部匹配所以为0)
            $data_lbw['yipipei_money']=$fk_yipipei_my+$fk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
            $FKUser->where('id=' . $fk_id)->save($data_lbw); //用付款订单序号
            //收款状态修改
            $data_lbwt['money_total'] = $sk_money - $fk_money;   //更新收款总匹配金额去除匹配掉部分
            $data_lbwt['yipipei_money']=$sk_yipp_money+$fk_money;           //更新已匹配金额,用已匹配加上现匹配
            $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
            $SKUser->where('id=' . $sk_id)->save($data_lbwt);
            $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复

        } elseif ($fk_money > $sk_money) {
            $SFUser = M("UserPipeioder"); //创建数据对象

            $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
            $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
            $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
            //双方匹配数据入库
            $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
            $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
            $data['dk_creattime'] = $creatTime;      //写入订单创建时间
            $data['dk_money_total'] = $sk_money; //付款的金额 这里因为收款金额小于付款,所以付款金额要用收款金额数量来存入
            $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
            $data['dk_dakuan_status'] = '0'; //写入等待打款
            $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
            $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
            $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
            $data['sk_money_total'] = $sk_money; //收款金额
            $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
            $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
            $data['sf_jy_status'] = '0'; //写入双方交易状态
            $data['sk_name'] = $sk_name; //写入收款人姓名
            $data['fk_name'] = $fk_name;//写入付款人姓名
            $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
            $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
            $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
            $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
            $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
            $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
            $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
            $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
            $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
            $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
            $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
            $data['dk_username']=$fk_username; //写入打款人用户名
            $data['sk_username']=$sk_username; //写入收款人用户名
            $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
            $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
            $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
            $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
            $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
            $SFUser->data($data)->add(); //数据入库
            //更改双方临时匹配数据表状态
            //付款状态修改
            $data_lbw['money_total'] = $fk_money-$sk_money;    //修改付款总金额余额状态
            $data_lbw['yipipei_money']=$fk_yipipei_my+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
            $FKUser->where('id=' . $fk_id)->save($data_lbw);
            //收款状态修改
            $data_lbwt['money_total'] = '0';    //修改收款总金额状态
            $data_lbwt['jiaoyi_zt'] = 1;  //修改匹配状态
            $data_lbwt['yipipei_money']=$sk_yipp_money+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
            $SKUser->where('id=' . $sk_id)->save($data_lbwt);
            $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复
        } // elseif($fk_yuanmoney = $sk_money)
        else {
            $SFUser = M("UserPipeioder"); //创建数据对象

            $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
            $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
            $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
            //双方匹配数据入库
            $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
            $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
            $data['dk_creattime'] = $creatTime;      //写入订单创建时间
            $data['dk_money_total'] = $fk_money; //付款的金额
            $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
            $data['dk_dakuan_status'] = '0'; //写入等待打款
            $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
            $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
            $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
            $data['sk_money_total'] = $sk_money; //收款金额
            $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
            $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
            $data['sf_jy_status'] = '0'; //写入双方交易状态
            $data['sk_name'] = $sk_name; //写入收款人姓名
            $data['fk_name'] = $fk_name;//写入付款人姓名
            $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
            $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
            $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
            $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
            $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
            $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
            $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
            $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
            $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
            $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
            $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
            $data['dk_username']=$fk_username; //写入打款人用户名
            $data['sk_username']=$sk_username; //写入收款人用户名
            $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
            $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
            $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
            $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
            $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
            $SFUser->data($data)->add(); //数据入库
            //更改双方临时匹配数据表状态
            //付款状态修改
            $data_lbw['money_total'] = "0";   //修改付款总金额状态
            $data_lbw['peidui_status'] = $fk_zhuangtai + 1;  //修改付款匹配状态
            $data_lbw['yipipei_money']=$fk_yipipei_my+$fk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
            $FKUser->where('id=' . $fk_id)->save($data_lbw);
            //收款状态修改
            $data_lbwt['money_total'] = "0";   //修改收款总金额状态
            $data_lbwt['jiaoyi_zt'] = 1;  //修改匹配状态
            $data_lbwt['yipipei_money']=$sk_yipp_money+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
            $SKUser->where('id=' . $sk_id)->save($data_lbwt);
            $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复

        }
        /*else{
                $SFUser=M("UserPipeioder"); //创建数据对象

                $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
                $orderSn = "SF".$yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
                $creatTime=date("Y-m-d H:i:s"); //订单创建时间生成
                //双方匹配数据入库
                $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
                $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
                $data['dk_creattime'] = $creatTime;      //写入订单创建时间
                $data['dk_money_total'] = $fk_money; //付款的金额
                $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
                $data['dk_dakuan_status'] = '0'; //写入等待打款
                $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
                $data['sk_lbw_order_pipei'] =$sk_dh; //收款订单号
                $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
                $data['sk_money_total'] =$sk_money; //收款金额
                $data['sk_skuan_status']='0'; //写入等待对方打款状态
                $data['sk_peiduifs'] =$sk_fangfa;//写入收款支持方法
                $data['sf_jy_status'] = '0'; //写入双方交易状态
                $data['sk_name']=$sk_name; //写入收款人姓名
                $data['fk_name']=$fk_name;//写入付款人姓名
                $data['dk_bank_number']=$fk_bankNumber;  //写入付款人银行账号
                $data['dk_bank_name']=$fk_bankName;     //写入付款人银行名称
                $data['dk_alipay']=$fk_alipay;   //写入付款人支付宝
                $data['dk_sj_mobile']=$fk_sj_mobile; //写入付款人上级手机
                $data['dk_my_mobile']=$fk_my_mobile; //写入付款人自己手机
                $data['sk_bank_number']=$sk_bankNumber; //写入收款人银行卡号
                $data['sk_bank_name']=$sk_bankName;  //写入收款人银行名称
                $data['sk_alipay']=$sk_alipay;   //写入收款人支付宝
                $data['sk_sj_mobile']=$sk_sj_mobile; //写入收款人上级手机
                $data['sk_my_mobile']=$sk_my_mobile;  //写入收款人自己手机
                $SFUser->data($data)->add(); //数据入库
                //更改双方临时匹配数据表状态
                //付款状态修改
                $data_lbw['yipipei_money']=$fk_money;   //修改付款已匹配金额状态
                $data_lbw['peidui_cishu']=$fk_cishu+1;  //修改付款次数
                $FKUser->where('id='.$fk_id)->save($data_lbw);
                //收款状态修改
                $data_lbw['yipipei_money']=$fk_money+$sk_yipp_money;   //修改已匹配金额状态
                $data_lbw['peidui_status']=$sk_zhuangtai+1;  //修改匹配状态
                $data_lbw['shoukuan_cishu']=$sk_cishu+1;   //修改收款次数
                $SKUser->where('id='.$sk_id)->save($data_lbw);
                $SKUser->where('lbw_vipid='.$fk_vipid)->setField('peidui_status','0'); //同会员获得帮助数据恢复
            }
        */


    }

    /*
     * 首次过后的匹配主体
     */
    public function makeMoneyPlan()
    {

        $FKUser = M("UserTemppipeiorder"); //实例化数据模型
        $SKUser = M("UserTempskorder");  //实例化数据模型
        //付款人
        $data['peidui_cishu'] = array('neq', 0);  //构造查询条件查询匹配次数不等于0的
        $data['peidui_status'] = array('eq', 0);  //构造查询条件查询订单状态为0的
        $data['money_total'] = array('gt', 0);//检测订单匹配金额必须大于0
        $data['creattimetwo']=array('LT',time());
        $data['jiaoyi_zt'] = array('neq', 9); //等于9就是处罚过冻结的订单无法继续完成交易
        $fk_sj = $FKUser->where($data)->order('creattime')->limit(1)->select(); //取出这个数据准备与收款方匹配
        $fk_yuanmoney = $fk_sj[0]["money_total"];//付款数据库直取金额
        $fk_money = $fk_yuanmoney; //付款金额
        $fk_vipid = $fk_sj[0]["lbw_vipid"];  //付款会员id
        $fk_dh = $fk_sj[0]["lbw_order_pipei"]; //付款匹配订单号
        $fk_fangfa = $fk_sj[0]["peiduifs"];   //付款匹配方法
        $fk_id = $fk_sj[0]["id"];           //匹配付款订单序号
        $fk_zhuangtai = $fk_sj[0]["peidui_status"]; //匹配状态
        $fk_cishu = $fk_sj[0]["peidui_cishu"];
        $fk_name = $fk_sj[0]['fk_name'];  //姓名
        $fk_bankNumber = $fk_sj[0]['bank_number'];
        $fk_bankName = $fk_sj[0]['bank_name'];
        $fk_alipay = $fk_sj[0]['alipay'];
        $fk_sj_mobile = $fk_sj[0]['fk_sj_mobile'];
        $fk_my_mobile = $fk_sj[0]['fk_my_mobile'];
        $fk_yipipei_my=$fk_sj[0]['yipipei_money']; //拿到已匹配金额数据
        $fk_username=$fk_sj[0]['username'];//拿到付款人用户名
        $fk_tuijianName=$fk_sj[0]['tuijianrenxm']; //打款推荐人姓名
        $fk_tuijianuserName=$fk_sj[0]['tjr_username']; //打款推荐人姓名存入
        $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '5'); //同会员获得帮助数据剔除
        

        //收款人
        $sk_data['money_total'] = array('gt', 0); ///构造总金额不等于零的收款数据查询
        $sk_data['jiaoyi_zt'] = array('eq', 0); //构造订单状态为0的收款配对查询
        $sk_data['jiaoyi_zt'] = array('neq', 9); //等于9就是处罚过冻结的订单无法继续完成交易
        $sk_data['peidui_status'] = array('neq', 5); //构造不会匹配到自己提现订单的条件
        $sk_sj = $SKUser->where($sk_data)->order('creattime')->limit(1)->select();
        $sk_money = $sk_sj[0]["money_total"];  //收款金额
        $sk_vipid = $sk_sj[0]["lbw_vipid"];   //收款会员id
        $sk_dh = $sk_sj[0]["lbw_order_sk_id"]; //收款订单号
        $sk_fangfa = $sk_sj[0]["peiduifs"];   //收款支持方法
        $sk_id = $sk_sj[0]["id"]; //匹配收款订单序号
        $sk_zhuangtai = $sk_sj[0]["peidui_status"];  //收款匹配状态
        $sk_cishu = $sk_sj[0]["shoukuan_cishu"];
        $sk_name = $sk_sj[0]['sk_name'];
        $sk_bankNumber = $sk_sj[0]['bank_number'];
        $sk_bankName = $sk_sj[0]['bank_name'];
        $sk_alipay = $sk_sj[0]['alipay'];
        $sk_sj_mobile = $sk_sj[0]['sk_sj_mobile'];
        $sk_my_mobile = $sk_sj[0]['sk_my_mobile'];
        $sk_yipp_money =  $sk_sj[0]['yipipei_money']; //已匹配金额数据
        $sk_username = $sk_sj[0]['username'];  //拿到收款人用户名
        $sk_qianbao=$sk_sj[0]['dt_qb']; //拿到钱包类型
        $sk_tuijianName=$sk_sj[0]['tuijianrenxinm']; //收款推荐人姓名存入
        $sk_tuijianuserName=$sk_sj[0]['tjr_username']; //收款推荐人姓名存入
        //双方入库主体
        if ($fk_money < $sk_money) {
            $SFUser = M("UserPipeioder"); //创建数据对象

            $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
            $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
            $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
            //双方匹配数据入库
            $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
            $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
            $data['dk_creattime'] = $creatTime;      //写入订单创建时间
            $data['dk_money_total'] = $fk_money; //付款的金额
            $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
            $data['dk_dakuan_status'] = '0'; //写入等待打款
            $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
            $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
            $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
            $data['sk_money_total'] = $sk_money; //收款金额
            $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
            $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
            $data['sf_jy_status'] = '0'; //写入双方交易状态
            $data['sk_name'] = $sk_name; //写入收款人姓名
            $data['fk_name'] = $fk_name;//写入付款人姓名
            $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
            $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
            $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
            $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
            $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
            $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
            $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
            $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
            $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
            $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
            $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
            $data['dk_username']=$fk_username; //写入打款人用户名
            $data['sk_username']=$sk_username; //写入收款人用户名
            $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
            $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
            $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
            $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
            $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
            $SFUser->data($data)->add(); //数据入库
            //更改双方临时匹配数据表状态
            //付款状态修改
            $data_lbw['money_total'] = '0';   //修改付款订单剩余匹配余额(付款小于收款，付款直接全部匹配所以为0)
            $data_lbw['yipipei_money']=$fk_yipipei_my+$fk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
            $FKUser->where('id=' . $fk_id)->save($data_lbw);
            //收款状态修改
            $data_lbwt['money_total'] = $sk_money - $fk_money;   //更新收款总匹配金额去除匹配掉部分
            $data_lbwt['yipipei_money']=$sk_yipp_money+$fk_money;           //更新已匹配金额,用已匹配加上现匹配
            $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
            $SKUser->where('id=' . $sk_id)->save($data_lbwt);
            $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复

        } elseif ($fk_money > $sk_money) {
            $SFUser = M("UserPipeioder"); //创建数据对象

            $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
            $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
            $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
            //双方匹配数据入库
            $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
            $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
            $data['dk_creattime'] = $creatTime;      //写入订单创建时间
            $data['dk_money_total'] = $sk_money; //付款的金额
            $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
            $data['dk_dakuan_status'] = '0'; //写入等待打款
            $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
            $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
            $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
            $data['sk_money_total'] = $sk_money; //收款金额
            $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
            $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
            $data['sf_jy_status'] = '0'; //写入双方交易状态
            $data['sk_name'] = $sk_name; //写入收款人姓名
            $data['fk_name'] = $fk_name;//写入付款人姓名
            $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
            $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
            $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
            $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
            $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
            $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
            $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
            $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
            $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
            $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
            $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
            $data['dk_username']=$fk_username; //写入打款人用户名
            $data['sk_username']=$sk_username; //写入收款人用户名
            $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
            $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
            $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
            $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
            $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
            $SFUser->data($data)->add(); //数据入库
            //更改双方临时匹配数据表状态
            //付款状态修改
            $data_lbw['money_total'] = $fk_money-$sk_money;    //修改付款总金额余额状态
            $data_lbw['yipipei_money']=$fk_yipipei_my+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
            $FKUser->where('id=' . $fk_id)->save($data_lbw);
            //收款状态修改
            $data_lbwt['money_total'] = '0';    //修改收款总金额状态
            $data_lbwt['jiaoyi_zt'] = 1;  //修改匹配状态
            $data_lbwt['yipipei_money']=$sk_yipp_money+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
            $SKUser->where('id=' . $sk_id)->save($data_lbwt);
            $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复
        } // elseif($fk_yuanmoney = $sk_money)
        else {
            $SFUser = M("UserPipeioder"); //创建数据对象

            $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
            $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
            $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
            //双方匹配数据入库
            $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
            $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
            $data['dk_creattime'] = $creatTime;      //写入订单创建时间
            $data['dk_money_total'] = $fk_money; //付款的金额
            $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
            $data['dk_dakuan_status'] = '0'; //写入等待打款
            $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
            $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
            $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
            $data['sk_money_total'] = $sk_money; //收款金额
            $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
            $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
            $data['sf_jy_status'] = '0'; //写入双方交易状态
            $data['sk_name'] = $sk_name; //写入收款人姓名
            $data['fk_name'] = $fk_name;//写入付款人姓名
            $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
            $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
            $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
            $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
            $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
            $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
            $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
            $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
            $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
            $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
            $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
            $data['dk_username']=$fk_username; //写入打款人用户名
            $data['sk_username']=$sk_username; //写入收款人用户名
            $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
            $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
            $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
            $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
            $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
            $SFUser->data($data)->add(); //数据入库
            //更改双方临时匹配数据表状态
            //付款状态修改
            $data_lbw['money_total'] = "0";   //修改付款总金额状态
            $data_lbw['peidui_status'] = $fk_zhuangtai + 1;  //修改付款匹配状态
            $data_lbw['yipipei_money']=$fk_yipipei_my+$fk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
            $FKUser->where('id=' . $fk_id)->save($data_lbw);
            //收款状态修改
            $data_lbwt['money_total'] = "0";   //修改收款总金额状态
            $data_lbwt['jiaoyi_zt'] = 1;  //修改匹配状态
            $data_lbwt['yipipei_money']=$sk_yipp_money+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
            $SKUser->where('id=' . $sk_id)->save($data_lbwt);
            $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复

        }
    }

    
    //打款匹配倒计时
    public function dkCountDown(){
        $databe['dk_lbw_order_pipei']=I('post.danhao');
        $pd_total=D('UserPipeioder')->where($databe)->getField('dk_dakuan_status');
        $dk_id =D('UserPipeioder')->where($databe)->getField('dk_lbw_vipid');

        if ($pd_total == 0) {
        date_default_timezone_set("Asia/Shanghai");//地区
        $datacig_pd['name'] = "LBW_PDDKDJSTS";
        $lbw_config_djs = D('SystemConfig')->where($datacig_pd)->getField('value');  //获取匹配打款倒计时天数设置
        $data_where['dk_lbw_order_pipei']=I('post.danhao');
        $data_time=D('UserPipeioder')->where($data_where)->getField('sf_dd_crt_time'); //拿到订单创建时间
        $timeUnix=strtotime($data_time); //加分钟后面的时间变量必须为unix时间戳，所以这里需要转换
        $newtime=date('Y-m-d H:i:s', strtotime("+" . $lbw_config_djs . " minute", $timeUnix));//生成倒数时间

        $zero1 = time();//当前时间
        $zero2 = strtotime($newtime);//$lbw_end_time);  //打款时间上限
        if ($zero1 > $zero2) {
            //超时处理代码待写
            $data_cx['id']=$dk_id;   //找到打款人id
            $data_dj['status']=0;    //冻结账户
            D('User')->where($data_cx)->save($data_dj);  //冻结账户
           $zhudanhao=D('UserPipeioder')->where($data_where)->getField('dk_odr_ordernumber'); //拿到打款人主单号
            $data_zdh['lbw_order_pipei']=$zhudanhao;
            $data_cr_dj['jiaoyi_zt']=9;
            D('UserTemppipeiorder')->where($data_zdh)->save($data_cr_dj); //冻结主单号
        } else {
            $days = floor(($zero2 - $zero1) / 86400);
            $hours = floor((($zero2 - $zero1) % 86400) / 3600);
            $minutes = floor((($zero2 - $zero1) % 3600) / 60);
            $seconds = floor(($zero2 - $zero1) % 60);
            echo $days . "天" . $hours . "时" . $minutes . "分" . $seconds;
        }
    } else {
            echo "";
         }

    }
    //收款确认倒计时
    public function skCountDown(){

        $databe['dk_lbw_order_pipei']=I('post.danhao');
        $pd_total=D('UserPipeioder')->where($databe)->getField('sf_jy_status');
        $sk_id =D('UserPipeioder')->where($databe)->getField('sk_lbw_vipid');

        if ($pd_total == 1 and $pd_total != 3) {
            date_default_timezone_set("Asia/Shanghai");//地区
           // $datacig_pd['name'] = "LBW_PDDKDJSTS";
            $lbw_config_djs = 1440;//D('SystemConfig')->where($datacig_pd)->getField('value');  //获取匹配打款倒计时天数设置
            $data_where['dk_lbw_order_pipei']=I('post.danhao');
            $data_time=D('UserPipeioder')->where($data_where)->getField('dk_time_now'); //拿到订单创建时间
            $newtime=date('Y-m-d H:i:s', strtotime("+" . $lbw_config_djs . " minute", $data_time));//生成倒数时间

            $zero1 = time();//当前时间
            $zero2 = strtotime($newtime);//$lbw_end_time);  //打款时间上限
            if ($zero1 > $zero2) {
                //超时自动确认,把自动确认函数代码都搬过来处理代码待写
                $uid = $sk_id;
                $sf_sc_dh = I('post.danhao');              //拿到交易号
                $dataif['dk_lbw_order_pipei'] = $sf_sc_dh;
                $if_jy_status = D('UserPipeioder')->where($dataif)->getField('sf_jy_status');

                    $data['dk_lbw_order_pipei'] = $sf_sc_dh; //构造双方数据库查询
                    $datalbw['sf_jy_status'] = '2';           //将交易状态变为成功
                    $b = D('UserPipeioder')->where($data)->save($datalbw); //更新交易状态
                    $oder_dh = D('UserPipeioder')->where($data)->getField('dk_odr_ordernumber'); //拿到打款匹配主单号
                    $jy_money = D('UserPipeioder')->where($data)->getField('dk_money_total');  //拿到交易成功金额
                    $dataodr['lbw_order_pipei'] = $oder_dh;                                 //构造主单号数据库查询
                    $yi_jiaoyi_money = D('UserTemppipeiorder')->where($dataodr)->getField('yijy_moeny');  //主单号已交易金额
                    $pp_jy_total = $yi_jiaoyi_money + $jy_money; //更新已交易金额
                    $datady['yijy_moeny'] = $pp_jy_total;
                    D('UserTemppipeiorder')->where($dataodr)->save($datady);  //数据入库
                    /*
                     * 进入将数据载入User数据表功能模块
                      */
                    $dk_user_name = D('UserPipeioder')->where($dataif)->getField('dk_lbw_vipid');//用双方交易单号找到打款人id
                    $dk_user_id['id'] = $dk_user_name;  //构造查询打款人数据
                    $dk_user_sj = D('User')->where($dk_user_id)->select(); //获取打款人user表数据
                    $dk_usernew_fktotal = $dk_user_sj[0]['lbw_fktotal'];  //取出打款总计老数据
                    $dk_usernew_fkcishu = $dk_user_sj[0]['lbw_fkcishu'];  //取出打款次数老数据
                    $dk_usernew_yuemy = $dk_user_sj[0]['user_jt_money_no'];  //取出打款人账户冻结余额
                    $dk_user_update['lbw_fktotal'] = $dk_usernew_fktotal + $jy_money;  //更新打款金额数据
                    $dk_user_update['user_jt_money_no'] = $dk_usernew_yuemy + $jy_money;  //更新用户静态冻结余额
                    $dk_user_update['lbw_fkcishu'] = $dk_usernew_fkcishu + 1;  //更新打款次数数据
                    $dk_user_update['last_dk_time'] = time(); //记录最后一次打款时间
                    D('User')->where($dk_user_id)->save($dk_user_update);   //写入user表更新完毕
                    //打款user表数据更新end
                    //打款userid
                    //检测订单所有金额是否完全完成
                    $two_dkmotoal_money = D('UserTemppipeiorder')->where($dataodr)->getField('money_total');//再次查询打款人订单总易金额
                    if ($two_dkmotoal_money == 0) {
                        $two_dk_zt['jiaoyi_zt'] = 2; //将交易状态变为2 表示成功
                        D('UserTemppipeiorder')->where($dataodr)->save($two_dk_zt);//入库
                    }

                    $oder_sk_dh = D('UserPipeioder')->where($data)->getField('sk_lbw_order_pipei'); //拿到收款主单号
                    $dataskodr['lbw_order_sk_id'] = $oder_sk_dh;                          //构造收款主单号收款数据查询
                    $sk_yjy_money = D('UserTempskorder')->where($dataskodr)->getField('yijy_moeny'); //收款已交易金额
                    $sk_yjy_total = $jy_money + $sk_yjy_money;  //更新收款已交易金额
                    $datask['yijy_moeny'] = $sk_yjy_total;
                    $abc = D('UserTempskorder')->where($dataskodr)->save($datask);
                    //收款User表数据更新end
                    //收款userid
                    $sk_user_name = D('UserPipeioder')->where($dataif)->getField('sk_lbw_vipid');//用双方交易号找到收款人
                    $sk_user_id['id'] = $sk_user_name;  //构造收款人查询数据
                    $sk_user_sj = D('User')->where($sk_user_id)->select(); //拿到收款人user表数据
                    $sk_usernew_fktotal = $sk_user_sj[0]['lbw_sktotal']; //拿到收款人收款总计金额
                    $sk_usernew_fkcishu = $sk_user_sj[0]['lbw_skcishu']; //拿到收款人收款总计次数
                    $sk_usernew_yuemy = $sk_user_sj[0]['user_jt_money_no']; //拿到收款人账户余额数据
                    $sk_user_update['lbw_sktotal'] = $sk_usernew_fktotal + $jy_money; //更新收款人总计金额
                    $sk_user_update['user_jt_money_no'] = $sk_usernew_yuemy - $jy_money; //更新收款人账户余额
                    $sk_user_update['lbw_skcishu'] = $sk_usernew_fkcishu + 1;  //更新收款人总次数
                    D('User')->where($sk_user_id)->save($sk_user_update);  //存入数据表
                    //收款人user表数据更新end

                    //检测订单所有金额是否完全完成
                    $two_skmotoal_money = D('UserTempskorder')->where($dataskodr)->getField('money_total');//再次查询收款人订单总易金额
                    $two_sk_zt['jiaoyi_zt'] = 2; //将交易状态变为2 表示成功
                    D('UserTempskorder')->where($dataskodr)->save($two_sk_zt);//入库


            } else {
                $days = floor(($zero2 - $zero1) / 86400);
                $hours = floor((($zero2 - $zero1) % 86400) / 3600);
                $minutes = floor((($zero2 - $zero1) % 3600) / 60);
                $seconds = floor(($zero2 - $zero1) % 60);
                echo $days . "天" . $hours . "时" . $minutes . "分" . $seconds;
            }
        } else {
            echo "";
        }

    }

    /*
     * 匹配确认打款倒计时功能
     */
    public function lbwCountdown()
    {
        $sf_sc_dh = 'SFF426380533733457';
        $dataif['dk_lbw_order_pipei'] = $sf_sc_dh;
        $if_jy_status = D('UserPipeioder')->where($dataif)->getField('sf_jy_status');
        $asakllskdl['asdsa'] = 0 + 1;

        $sk_user_name = D('UserPipeioder')->where($dataif)->getField('sk_lbw_vipid');
        $sk_user_id['id'] = $sk_user_name;
        $sk_user_sj = D('User')->where($sk_user_id)->select();
        $sk_usernew_fktotal = $sk_user_sj[0]['lbw_sktotal'];
        $sk_usernew_fkcishu = $sk_user_sj[0]['lbw_skcishu'];
        $sk_user_update['lbw_sktotal'] = $sk_usernew_fktotal + 30;
        $sk_user_update['lbw_skcishu'] = $sk_usernew_fkcishu + 30;
        D('User')->where($sk_user_id)->save($sk_user_update);
    }

    //新注册用户倒计时
    public function lbwRegNewCount()
    {
        $uid = $this->is_login();
        $databe['id'] = $uid;
        $pd_total = D('User')->where($databe)->getField('lbw_paidancount');
        if ($pd_total == 0) {
            $data['id'] = $uid;   //取出用户ID
            $user_cTime = D('User')->where($data)->getField('ctime');  //取出用户创建时间
            $datacig['name'] = "LBW_REGTIME_DJ";    //构造查询数据
            $lbw_config_time = D('SystemConfig')->where($datacig)->getField('value'); //拿到系统设置时间参数
            $lbw_end_time = date('Y-m-d H:i:s', strtotime("+" . $lbw_config_time . " minute", $user_cTime));
            //上面把用户时间和系统设置时间相加
            date_default_timezone_set("Asia/Shanghai");//地区
            $zero1 = time();//当前时间
            $zero2 = strtotime($lbw_end_time);//$lbw_end_time);  //过年时间
            if ($zero1 > $zero2) {
                $jinyong['status'] = 0;
                D('User')->where($data)->save($jinyong);
            } else {
                $days = floor(($zero2 - $zero1) / 86400);
                $hours = floor((($zero2 - $zero1) % 86400) / 3600);
                $minutes = floor((($zero2 - $zero1) % 3600) / 60);
                $seconds = floor(($zero2 - $zero1) % 60);
                echo "首次打款剩余时间(超时账户注销):" . $days . "天" . $hours . "时" . $minutes . "分" . $seconds . "秒";
            }
        } else {
            echo "";
        }
    }
    

    //提供帮助列表明细页面
    public function pdlist()
    {
        $uid = $this->is_login();
        $user_info = D('User')->where($con)->find($uid);
        $map['lbw_vipid'] = $uid;
        $pdlist['dk_lbw_vipid'] = $uid;
        $pdlist['sf_jy_status']=array('neq',8);
        $category_info = D('UserTemppipeiorder')->where($map)->field('id,peidui_status,lbw_order_pipei,creattime,money_total')->limit(50)->select();
        $category = D('UserPipeioder')->where($pdlist)->limit(50)->select();
        $this->assign('meta_title', '提供帮助列表');
        $this->assign('user_id', $user_info['username']);
        $this->assign('user_username', $user_info['id']);
        $this->assign('user_time', $user_info['ctime']);
        $this->assign('user_jtmoney', $user_info['user_jt_money']);
        $this->assign('user_pd', $user_info['lbw_paidancount']);
        $this->assign('user_zj', $user_info['lbw_fktotal']);
        $this->assign('user_fkb', $user_info['lbw_fkcishu']);
        $this->assign('user_jt_ye',$user_info['user_jt_money']);
        $this->assign('user_dt_ye',$user_info['user_dt_money']);
        $this->assign('lbwlist', $category_info);
        $this->assign('lbwsf', $category);
        $this->display();
    }

    //获得帮助列表明细页面
    public function gdlist()
    {
        $uid = $this->is_login();
        $user_info = D('User')->where($con)->find($uid);
        $map['lbw_vipid'] = $uid;
        $gdlist['sk_lbw_vipid'] = $uid;
        $gdlist['sf_jy_status']=array('neq',8);
        $category_info = D('UserTempskorder')->where($map)->field('id,peidui_status,lbw_order_sk_id,creattime,money_total')->limit(50)->select();
        $category = D('UserPipeioder')->where($gdlist)->limit(50)->select();
        $this->assign('meta_title', '获得帮助列表');
        $this->assign('user_id', $user_info['username']);
        $this->assign('user_username', $user_info['id']);
        $this->assign('user_time', $user_info['ctime']);
        $this->assign('user_jtmoney', $user_info['user_jt_money']);
        $this->assign('user_pda', $user_info['lbw_paidancount']);
        $this->assign('lbwlist', $category_info);
        $this->assign('user_jt_ye',$user_info['user_jt_money']);
        $this->assign('user_jtdj_ye',$user_info['user_jt_money_no']);
        $this->assign('user_dt_ye',$user_info['user_dt_money']);
        $this->assign('sktotal',$user_info['lbw_sktotal']);
        $this->assign('skcishu',$user_info['lbw_skcishu']);
        $this->assign('lbwsf', $category);
        $this->display();
    }

    //提交打款处理函数
    public function submitGetHelp()
    {
        $uid = $this->is_login();
        $mypayff = I('post.mypayff');
        $fk_beizhu = I('post.fk_beizhu');
        $sf_sc_dh = I('post.sf_sc_dh');
        $data['dk_lbw_order_pipei'] = $sf_sc_dh;
        $fk_status = D('UserPipeioder')->where($data)->getField('sf_jy_status');
        // 上传文件

        if ($fk_status == 0) {
            $upload = new \Think\Upload();
            $fk_picture = $upload->uploadOne($_FILES['fk_picture']);
            if (!$fk_picture) {
                $this->error($upload->getError());
            } else {
                $address = "/uploads/" . $fk_picture['savepath'] . $fk_picture['savename'];
                $datalbw['fk_xz_pay'] = $mypayff;
                $datalbw['dk_dakuan_img'] = $address;
                $datalbw['dk_dakuan_status'] = '1';
                $datalbw['sf_jy_status'] = '1';
                $datalbw['dk_beizhu'] = $fk_beizhu;
                $datalbw['dk_time_now']=time();
                $b = D('UserPipeioder')->where($data)->save($datalbw);
                $this->success('打款成功,系统已经通知收款会员请耐心等待' . $b, U('User/center'));
            }

        } else {
            $this->error('订单状态为不能够打款,可能已经打过或者被冻结！', U('User/center'));
        }
    }

//确认打款处理函数
    public function submitGdList()
    {
        $uid = $this->is_login();
        $sf_sc_dh = $_GET['dd'];              //拿到交易号
        $dataif['dk_lbw_order_pipei'] = $sf_sc_dh;
        $if_jy_status = D('UserPipeioder')->where($dataif)->getField('sf_jy_status');

        if ($if_jy_status == 1) {
            $data['dk_lbw_order_pipei'] = $sf_sc_dh; //构造双方数据库查询
            $datalbw['sf_jy_status'] = '2';           //将交易状态变为成功
            $datalbw['jy_wancheng_time']=time();  //记录交易完成时间
            $b = D('UserPipeioder')->where($data)->save($datalbw); //更新交易状态
            $oder_dh = D('UserPipeioder')->where($data)->getField('dk_odr_ordernumber'); //拿到打款匹配主单号
            $jy_money = D('UserPipeioder')->where($data)->getField('dk_money_total');  //拿到交易成功金额
            $dataodr['lbw_order_pipei'] = $oder_dh;                                 //构造主单号数据库查询
            $yi_jiaoyi_money = D('UserTemppipeiorder')->where($dataodr)->getField('yijy_moeny');  //主单号已交易金额
            $pp_jy_total = $yi_jiaoyi_money + $jy_money; //更新已交易金额
            $datady['yijy_moeny'] = $pp_jy_total;
            D('UserTemppipeiorder')->where($dataodr)->save($datady);  //数据入库
            /*
             * 进入将数据载入User数据表功能模块
              */
            $dk_user_name = D('UserPipeioder')->where($dataif)->getField('dk_lbw_vipid');//用双方交易单号找到打款人id
            $dk_user_id['id'] = $dk_user_name;  //构造查询打款人数据
            $dk_user_sj = D('User')->where($dk_user_id)->select(); //获取打款人user表数据
            $dk_usernew_fktotal = $dk_user_sj[0]['lbw_fktotal'];  //取出打款总计老数据
            $dk_usernew_fkcishu = $dk_user_sj[0]['lbw_fkcishu'];  //取出打款次数老数据
            $dk_usernew_yuemy = $dk_user_sj[0]['user_jt_money_no'];  //取出打款人账户余额
            $dk_user_update['lbw_fktotal'] = $dk_usernew_fktotal + $jy_money;  //更新打款金额数据
            $dk_user_update['user_jt_money_no'] = $dk_usernew_yuemy + $jy_money;  //更新用户静态余额
            $dk_user_update['lbw_fkcishu'] = $dk_usernew_fkcishu + 1;  //更新打款次数数据
            $dk_user_update['last_dk_time'] = time(); //记录最后一次打款时间
            D('User')->where($dk_user_id)->save($dk_user_update);   //写入user表更新完毕
            //打款user表数据更新end
            //打款userid
            //检测订单所有金额是否完全完成
            $two_dkmotoal_money = D('UserTemppipeiorder')->where($dataodr)->getField('money_total');//再次查询打款人订单总易金额
            if ($two_dkmotoal_money == 0) {
                $two_dk_zt['jiaoyi_zt'] = 2; //将交易状态变为2 表示成功
                $two_dk_zt['creattimethree'] = time(); //录入交易成功时间
                $two_dk_zt['ketixian_zt'] = 1; //设置提现状态
                D('UserTemppipeiorder')->where($dataodr)->save($two_dk_zt);//入库
            }

            $oder_sk_dh = D('UserPipeioder')->where($data)->getField('sk_lbw_order_pipei'); //拿到收款主单号
            $dataskodr['lbw_order_sk_id'] = $oder_sk_dh;                          //构造收款主单号收款数据查询
            $sk_yjy_money = D('UserTempskorder')->where($dataskodr)->getField('yijy_moeny'); //收款已交易金额
            $sk_qianbaoType = D('UserTempskorder')->where($dataskodr)->getField('dt_qb'); //收款已交易金额
            $sk_yjy_total = $jy_money + $sk_yjy_money;  //更新收款已交易金额
            $datask['yijy_moeny'] = $sk_yjy_total;
            $abc = D('UserTempskorder')->where($dataskodr)->save($datask);

            if($sk_qianbaoType == 0){
            //收款User表数据更新end  静态钱包提现数据更新
            //收款userid
            $sk_user_name = D('UserPipeioder')->where($dataif)->getField('sk_lbw_vipid');//用双方交易号找到收款人
            $sk_user_id['id'] = $sk_user_name;  //构造收款人查询数据
            $sk_user_sj = D('User')->where($sk_user_id)->select(); //拿到收款人user表数据
            $sk_usernew_fktotal = $sk_user_sj[0]['lbw_sktotal']; //拿到收款人收款总计金额
            $sk_usernew_fkcishu = $sk_user_sj[0]['lbw_skcishu']; //拿到收款人收款总计次数
            $sk_usernew_yuemy = $sk_user_sj[0]['user_jt_money_no']; //拿到收款人账户余额数据
            $sk_user_update['lbw_sktotal'] = $sk_usernew_fktotal + $jy_money; //更新收款人总计金额
            $sk_user_update['user_jt_money_no'] = $sk_usernew_yuemy - $jy_money; //更新收款人账户余额
            $sk_user_update['lbw_skcishu'] = $sk_usernew_fkcishu + 1;  //更新收款人总次数
            D('User')->where($sk_user_id)->save($sk_user_update);  //存入数据表
            //收款人user表数据更新end
            }else{    //动态钱包提现数据更新
                $sk_user_name = D('UserPipeioder')->where($dataif)->getField('sk_lbw_vipid');//用双方交易号找到收款人
                $sk_user_id['id'] = $sk_user_name;  //构造收款人查询数据
                $sk_user_sj = D('User')->where($sk_user_id)->select(); //拿到收款人user表数据
                $sk_usernew_fktotal = $sk_user_sj[0]['lbw_sktotal']; //拿到收款人收款总计金额
                $sk_usernew_fkcishu = $sk_user_sj[0]['lbw_skcishu']; //拿到收款人收款总计次数
                $sk_usernew_yuemy = $sk_user_sj[0]['user_dt_money_no']; //拿到收款人账户余额数据
                $sk_user_update['lbw_sktotal'] = $sk_usernew_fktotal + $jy_money; //更新收款人总计金额
                $sk_user_update['user_dt_money_no'] = $sk_usernew_yuemy - $jy_money; //更新收款人账户余额
                $sk_user_update['lbw_skcishu'] = $sk_usernew_fkcishu + 1;  //更新收款人总次数
                D('User')->where($sk_user_id)->save($sk_user_update);  //存入数据表
            }
            //检测订单所有金额是否完全完成
            $two_skmotoal_money = D('UserTempskorder')->where($dataskodr)->getField('money_total');//再次查询收款人订单总易金额
            if ($two_skmotoal_money == 0) {
                $two_sk_zt['jiaoyi_zt'] = 2; //将交易状态变为2 表示成功
                $two_sk_zt['creattimetwo'] = time(); //录入交易成功时间
                D('UserTempskorder')->where($dataskodr)->save($two_sk_zt);//入库
            }
            if ($abc > 0) {
                $this->success('恭喜您交易成功！', U('User/center'));
            } else {
                $this->error('交易异常请联系客服', U('User/center'));
            }
        } else {
            $this->error('请不要重复确认!或者您的订单状态异常!', U('User/center'));
        }

        /*  if($yi_pipei_money = $jy_money){   //判断主单号已匹配金额与交易金额是否相等
              $datady['yipipei_money']="0";   //已匹配金额归0
              $datady['yijy_moeny']=$yi_jiaoyi_money + $jy_money;  //计算并构造已交易金额数据
              $abc=D('UserTemppipeiorder')->where($dataodr)->save($datady);  //数据入库
              if($abc>0){
              $this->success('恭喜您交易成功！', U('User/gdlist'));
              }
              else{
              $this->error('交易异常请联系客服', U('User/gdlist'));
              }
          }else{
              $sy_pp_money=abs($yi_pipei_money-$jy_money);  //计算主单号剩余匹配金额
              $datady['yipipei_money']=$sy_pp_money;       //更新已匹配金额
              $datady['yijy_moeny']=$yi_jiaoyi_money+$jy_money;  //更新已交易金额
              $abc=D('UserTemppipeiorder')->where($dataodr)->save($datady);
              if($abc>0){
                  $this->success('恭喜您交易成功！', U('User/gdlist'));
              }
              else{
                  $this->error('交易异常请联系客服', U('User/gdlist'));
              }
          }
        */

    }
//冻结
    public function fkDJSjc(){
        $databe['lbw_order_pipei']=I('post.danhao');
        $newtime=D('UserTemppipeiorder')->where($databe)->getField('creattimethree');
         $ketixian_stats=D('UserTemppipeiorder')->where($databe)->getField('ketixian_zt');
        if($ketixian_stats != 2){
        $datacig['name'] = "LBW_PIPEIDJ_TIME";    //构造查询数据
        $lbw_config_time = D('SystemConfig')->where($datacig)->getField('value'); //拿到系统设置时间参数
        $lbw_end_time = date('Y-m-d H:i:s', strtotime("+" . $lbw_config_time . " minute", $newtime));
        $zero1=time();
        $zero2=strtotime($lbw_end_time); //格式化判断时间
        if ($zero1 > $zero2) {
            $date_bc['ketixian_zt']=2;
            D('UserTemppipeiorder')->where($databe)->save($date_bc);
        } else {
            $days = floor(($zero2 - $zero1) / 86400);
            $hours = floor((($zero2 - $zero1) % 86400) / 3600);
            $minutes = floor((($zero2 - $zero1) % 3600) / 60);
            $seconds = floor(($zero2 - $zero1) % 60);
            echo $days . "天" . $hours . "时" . $minutes . "分" . $seconds;
        }
        }else{
            echo '';
        }
    }

//申诉请示函数
    public function shensu()
    {
        $uid = $this->is_login();
        $sf_sc_dh = $_GET['dd'];              //拿到交易号
        $dataif['dk_lbw_order_pipei'] = $sf_sc_dh;  //构造数据
        $if_jy_status = D('UserPipeioder')->where($dataif)->getField('sf_jy_status');  //拿到双方交易状态
        if ($if_jy_status == 3 or $if_jy_status == 2) {
            $this->error('错误！交易已成功或者正在申诉处理中', U('User/center'));
        } else {
            $data['sf_jy_status'] = "3";
            D('UserPipeioder')->where($dataif)->save($data);
            $this->success('申诉成功请稍后继续点击交易操作红色按钮上传交易凭证', U('User/center'));
        }
    }

//付款人凭证上传函数
    public function fkPingZheng()
    {
        $uid = $this->is_login();
        $sf_sc_dh = I('post.dddd');
        $dataif['dk_lbw_order_pipei'] = $sf_sc_dh;
        $status_ss = D('UserPipeioder')->where($dataif)->getField('fk_pingzheng_zt');
        if ($status_ss == 0) {
            $upload = new \Think\Upload();
            $fk_ss_picture = $upload->uploadOne($_FILES['shensu_picture']);
            if (!$fk_ss_picture) {
                $this->error($upload->getError());
            } else {
                $stauts_sk = D('UserPipeioder')->where($dataif)->getField('sk_pingzheng_zt');
                if ($stauts_sk == 1) {
                    $shoukuan['sf_jy_status'] = 4;
                    D('UserPipeioder')->where($dataif)->save($shoukuan);
                }

                $address = "/uploads/" . $fk_ss_picture['savepath'] . $fk_ss_picture['savename'];
                $data['fk_pingzheng_zt'] = 1;
                $data['dk_pingzheng_jf'] = $address;
                $data['fk_ts_miaoshu'] = I('post.shensu_beizhu');
                D('UserPipeioder')->where($dataif)->save($data);
                $this->success('凭证提交成功请等候处理', U('User/center'));
            }
        } else {
            $this->error('错误，请不要重复提交凭证！', U('User/center'));
        }
    }

//收款人凭证上传函数
    public function skPingZheng()
    {
        $uid = $this->is_login();
        $sf_sc_dh = I('post.dddd');
        $dataif['dk_lbw_order_pipei'] = $sf_sc_dh;
        $status_ss = D('UserPipeioder')->where($dataif)->getField('sk_pingzheng_zt');
        if ($status_ss == 0) {
            $upload = new \Think\Upload();
            $sk_ss_picture = $upload->uploadOne($_FILES['shensu_picture']);
            if (!$sk_ss_picture) {
                $this->error($upload->getError());
            } else {
                $stauts_fk = D('UserPipeioder')->where($dataif)->getField('fk_pingzheng_zt');
                if ($stauts_fk == 1) {
                    $shoukuan['sf_jy_status'] = 4;
                    D('UserPipeioder')->where($dataif)->save($shoukuan);
                }

                $address = "/uploads/" . $sk_ss_picture['savepath'] . $sk_ss_picture['savename'];
                $data['sk_pingzheng_zt'] = 1;
                $data['sk_pingzheng_jf'] = $address;
                $data['sk_ts_miaoshu'] = I('post.shensu_beizhu');
                D('UserPipeioder')->where($dataif)->save($data);
                $this->success('凭证提交成功请等候处理', U('User/center'));
            }
        } else {
            $this->error('错误，请不要重复提交凭证！', U('User/center'));
        }
    }

    //删除提供帮助排队订单
    public function Removepdlist()
    {
        $id = $_GET['id'];
        $pdcs=D('UserTemppipeiorder')->where('id='.$id)->getField('peidui_cishu');
        if($pdcs != 0){
            $this->error('您的订单已匹配不能删除',U('User/center'));
        }else {
            $strats = D('UserTemppipeiorder')->delete($id);
            if ($strats == 1) {
                $this->success('删除成功', U('User/center'));
            } else {
                $this->error('删除失败！', U('User/center'));
            }
        }

    }

    //删除获得帮助排队订单
    public function Removegdlist()
    {
        $id = $_GET['id'];
        $type=D('UserTempskorder')->where('id='.$id)->getField('dt_qb');;
        $uid = $this->is_login();
        $pdcs =D('UserTempskorder')->where('id='.$id)->getField('shoukuan_cishu');
        if($type==0){

        if($pdcs != 0){
            $this->error('您的订单已匹配不能删除',U('User/center'));
        }else {
            $dq_jy_je=D('UserTempskorder')->where('id='.$id)->getField('money_total'); //交易金额
            $dq_dj_qb=D('User')->where('id='.$uid)->getField('user_jt_money_no');  //静态冻结钱包余额
            $huifuje=$dq_dj_qb-$dq_jy_je;  //恢复之前冻结余额金额
            $data['user_jt_money_no']=$huifuje; //恢复冻结金额之前余额
            D('User')->where('id='.$uid)->save($data);
            $dq_jt_je=D('User')->where('id='.$uid)->getField('user_jt_money'); //获得用户静态钱包余额
            $upjtye=$dq_jt_je+$dq_jy_je;  //交易金额 加 静态钱包余额 恢复之前静态钱包余额
            $data_up['user_jt_money']=$upjtye;
            D('User')->where('id='.$uid)->save($data_up);
            $strats = D('UserTempskorder')->delete($id);
            if ($strats == 1) {
                $this->success('删除成功', U('User/center'));
            } else {
                $this->error('删除失败！', U('User/center'));
            }
        }
        }else{ //动态钱包订单删除
            if($pdcs != 0){
                $this->error('您的订单已匹配不能删除',U('User/center'));
            }else {
                $dq_jy_je=D('UserTempskorder')->where('id='.$id)->getField('money_total'); //交易金额
                $dq_dj_qb=D('User')->where('id='.$uid)->getField('user_dt_money_no');  //动态冻结钱包余额
                $huifuje=$dq_dj_qb-$dq_jy_je;  //恢复之前冻结余额金额
                $data['user_dt_money_no']=$huifuje; //恢复冻结金额之前余额
                D('User')->where('id='.$uid)->save($data);
                $dq_jt_je=D('User')->where('id='.$uid)->getField('user_dt_money'); //获得用户动态钱包余额
                $upjtye=$dq_jt_je+$dq_jy_je;  //交易金额 加 动态钱包余额 恢复之前动态钱包余额
                $data_up['user_dt_money']=$upjtye;
                D('User')->where('id='.$uid)->save($data_up);
                $strats = D('UserTempskorder')->delete($id);
                if ($strats == 1) {
                    $this->success('删除成功', U('User/center'));
                } else {
                    $this->error('删除失败！', U('User/center'));
                }
            }
        }
    }

//家族树状图
    public function tree()
    {
        $uid = $this->is_login();
        $user_info = D('User')->where($con)->find($uid);
        $this->assign('meta_title', '个人中心');
        $this->assign('user_id', $user_info['username']);
        $this->assign('user_username', $user_info['id']);
        $aoao['id'] = $uid;
        $ab = D('User')->where($aoao)->getField('tuijianrenku');

        // $as=D('UserTuiguang')->select();
        $oo = explode(',', $ab);
        $tt = count($oo);
        $as = array();
        $c = 0;
        for ($i = 0; $i < $tt; $i++) {
            $ooo['id'] = array('EQ', $oo[$i]);
            $as[$c] = D('UserTuiguang')->where($ooo)->getField('id,parentId,name');
            $c = $c + 1;
        }
        foreach ($as as $value) {
            foreach ($value as $v) {
                $arr2[] = $v;
            }
        }
        //  echo "<pre>";var_dump($as);echo "<pre>";
        echo JSON_ENCODE($arr2);


        //echo JSON_ENCODE(array_values($as));
        // echo JSON_ENCODE($as);
    }

//家族
    public function family()
    {
        $uid = $this->is_login();
        $user_info = D('User')->where($con)->find($uid);
        $this->assign('meta_title', '个人中心');
        $this->assign('user_id', $user_info['username']);
        $this->assign('user_username', $user_info['id']);
        $this->assign('user_time', $user_info['ctime']);
        $this->assign('user_jtmoney', $user_info['user_jt_money']);
        $this->assign('user_pda', $user_info['lbw_paidancount']);
        $this->assign('user_jt_ye',$user_info['user_jt_money']);
        $this->assign('user_dt_ye',$user_info['user_dt_money']);
        $ooo['lbw_tuijianren'] = array('EQ', $uid);
        $abb = D('User')->where($ooo)->select();
        $this->assign('tuijianren', $abb);
        $this->display();


    }

//符合发放普通打款利息订单载入利息表功能
    public function moneyday()
    {
        $dataif['sf_jy_status'] = array('NEQ', 3);
        $dataif['lixi_if_fafang'] = array('EQ', 0);
        $lixi_a = D('UserPipeioder')->where($dataif)->select();
        $datacig_bfb['name'] = "LBW_ZYLXLV_DY"; //获取利率设置
        $lbw_config_lx = D('SystemConfig')->where($datacig_bfb)->getField('value');
        $b = count($lixi_a);
        $lbw_config_time = 1440;
        date_default_timezone_set("Asia/Shanghai");
        for ($i = 0; $i < $b; $i++) {
            $data_user_ll['id'] = $lixi_a[$i]['dk_lbw_vipid'];
            $lilv = D('User')->where($data_user_ll)->getField('LBW_FORLIXI_YJ');
            $creatTime = date("Y-m-d H:i:s"); //利息表创建时间生成
            $creatTime_t = strtotime($creatTime);
            $data['dk_sf_jydh'] = $lixi_a[$i]['dk_lbw_order_pipei'];
            $data['dk_lbw_vipid'] = $lixi_a[$i]['dk_lbw_vipid'];
            $data['username']=$lixi_a[$i]['dk_username'];; //用户名
            $data['fk_crt_time'] = $lixi_a[$i]['sf_dd_crt_time'];
            $data['lixi_time'] = $creatTime;
            $data['yuji_time'] = date('Y-m-d H:i:s', strtotime("+" . $lbw_config_time . " minute", $creatTime_t));
            $data['lixi_money'] = $lixi_a[$i]['dk_money_total'] * ($lbw_config_lx + $lilv);
            $data['lixi_total_day'] = 1;
            $data['dk_money_total'] = $lixi_a[$i]['dk_money_total'];
            $data['sf_jy_status'] = $lixi_a[$i]['sf_jy_status'];
            $data['dk_dakuan_status'] = $lixi_a[$i]['dk_dakuan_status'];
            $data['meiri_yingfa']=$lixi_a[$i]['dk_money_total'] *($lbw_config_lx + $lilv);
            D('UserLixi')->add($data);
            //user表中更改动态钱包的冻结余额
            $dj_yue_money = D('User')->where($data_user_ll)->getField('user_dt_money_no');
            //以下是更新冻结动态余额
            $newDTdj_money_update['user_dt_money_no'] = $dj_yue_money + $lixi_a[$i]['dk_money_total'] * ($lbw_config_lx + $lilv);
            D('User')->where($data_user_ll)->save($newDTdj_money_update);
            //改变双方交易单号的利息表创建状态
            $data_ys_li_zt['lixi_if_fafang'] = 1;
            $data_ys_user['dk_lbw_order_pipei'] = $lixi_a[$i]['dk_lbw_order_pipei'];
            D('UserPipeioder')->where($data_ys_user)->save($data_ys_li_zt);
        }
    }

//普通打款利息每日计算功能
    public function moenyCountDay()
    {
        $datacig_bfb['name'] = "LBW_ZYLXLV_DY"; //获取利率设置
        $lbw_config_lx = D('SystemConfig')->where($datacig_bfb)->getField('value');//获取利率设置
        $lixi_chushihua = D('UserLixi')->select(); //利息数据初始化
        $a = count($lixi_chushihua); //获得利息表数据总数
        //循环进行主单号交易状态检测以及更新利息表中交易状态和打款状态数据
        for ($i = 0; $i < $a; $i++) {
            $chaxun_dk_dh = $lixi_chushihua[$i]['dk_sf_jydh'];  //拿到双方交易号也是利息号
            //  $sf_jy_status=$lixi_chushihua[$i]['sf_jy_status']; //拿到双方交易状态
            //   $dk_dakuan_status=$lixi_chushihua[$i]['dk_dakuan_status']; //拿到双方打款状态

            //开始构造产生利息交易的数据查询
            $data['dk_lbw_order_pipei'] = $chaxun_dk_dh;
            $b = D('UserPipeioder')->where($data)->select(); //获取指定匹配中并且获得利息的订单数据
            $bb = $b[0]['dk_dakuan_status']; //获得最新打款状态
            $cc = $b[0]['sf_jy_status'];   //获得最新交易状态
            $data_lixi['dk_dakuan_status'] = $bb;
            $data_lixi['sf_jy_status'] = $cc;
            $data_cxlx['dk_sf_jydh'] = $chaxun_dk_dh;
            D('UserLixi')->where($data_cxlx)->save($data_lixi);
        }
        //开始进行利息发放
        $data_ra['sf_jy_status'] = array('NEQ', 3);
        $data_ra['sf_jy_status'] = array('NEQ', 8);
        $ee = D('UserLixi')->where($data_ra)->select();//拿出交易状态不为纠纷的利息订单
        $lbw_config_time = 1440;//设置每日
        date_default_timezone_set("Asia/Shanghai");
        $lixi_sz_zs = count($ee); //拿到数据总数
        //循环遍历更新数据开始
        for ($o = 0; $o < $lixi_sz_zs; $o++) {
            $data_user_ll['id'] = $ee[$o]['dk_lbw_vipid'];
            $lilv = D('User')->where($data_user_ll)->getField('LBW_FORLIXI_YJ');
            //上面是查找会员永久增加的利率

            $lixi_time_l = $ee[$o]['yuji_time'];
            $lixi_time_unix = strtotime($lixi_time_l);
            $nowTime = time();
            //检测开始发放利息 判断是否满一天
            if ($nowTime > $lixi_time_unix) {
                $lixi_money_day = $ee[$o]['dk_money_total'] * ($lbw_config_lx + $lilv);
                $creatTime = date("Y-m-d H:i:s"); //利息发放预计新时间生成
                $creatTime_t = strtotime($creatTime);//转换unix时间戳
                $lixi_Newtime = date('Y-m-d H:i:s', strtotime("+" . $lbw_config_time . " minute", $creatTime_t));//增加一天
                $lixi_day_total = $ee[$o]['lixi_total_day'] + 1; //获得利息天数加1
                $lixi_ye = $lixi_money_day + $ee[$o]['lixi_money']; //更新利息后要存入利息表余额的余额
                //准备构造存入利息表数据
                $data_new['yuji_time'] = $lixi_Newtime; //新的发放时间
                $data_new['lixi_total_day'] = $lixi_day_total; //利息发放天数加1
                $data_new['lixi_money'] = $lixi_ye; //存入新的余额
                $date_new_sj['dk_sf_jydh'] = $ee[$o]['dk_sf_jydh'];
                D('UserLixi')->where($date_new_sj)->save($data_new); //存入数据
                //开始更新user表中冻结的动态钱包余额
                $dj_yue_money = D('User')->where($data_user_ll)->getField('user_dt_money_no'); //获得动态冻结钱包余额
                $User_data_new['user_dt_money_no'] = $dj_yue_money + $lixi_money_day; //更新冻结动态钱包余额
                D('User')->where($data_user_ll)->save($User_data_new);  //存入数据
            }
        }

    }

    //交易完成冻结检测
    public function jiaoyiwancheng(){
        
    }

    //推广奖励利息计算
    public function UserTgJl(){
        $data['status']=array('NEQ',0);
        $data['id']=array('NEQ',1);
        $User_a=D('User')->where($data)->select();
        $User_total=count($User_a);
        $datacig_v2['name'] = "LBW_VTWO_USER"; //获取v2设置
        $lbw_config_v2 = D('SystemConfig')->where($datacig_v2)->getField('value');//获取v2设置
        $datacig_v3['name'] = "LBW_VTHREE_USER"; //获取v3设置
        $lbw_config_v3 = D('SystemConfig')->where($datacig_v3)->getField('value');//获取v3设置
        $datacig_v4['name'] = "LBW_VFOUR_USER"; //获取v4设置
        $lbw_config_v4 = D('SystemConfig')->where($datacig_v4)->getField('value');//获取v4设置
        //开始更新用户等级
        for($i=0;$i<$User_total;$i++){
            $user_id=$User_a[$i]['id']; //准备开始遍历每一个用户
            $data_two['lbw_tuijianren']=$user_id; //构造推广表查询数据,要查询的id
            $data_two['status']=array('NEQ',0);
            $data_two['lbw_fkcishu']=array('NEQ',0); //付款次数不等于0
            $User_b=D('User')->where($data_two)->select(); //取出所有符合规则的直推下线数据
            $a=count($User_b);
            //v2会员检测
            if($a>=$lbw_config_v2){
                $data_three['lbw_tuijianren']=$user_id;
                $data_three['status']=array('NEQ',0);
                $data_three['lbw_fkcishu']=array('NEQ',0); //付款次数不等于0
                $data_three['lbw_viplevel']=array('EQ',2); //用户等级等于v3的会员
                $User_c=D('User')->where($data_three)->select();
                $b=count($User_c);
                if($a>=$lbw_config_v3){
                    $data_vth['lbw_tuijianren']=$user_id;//这判断体里写v3规则
                    $data_cr_vth['lbw_viplevel']=2;
                    D('User')->where($data_vth)->save($data_cr_vth);
                }elseif($b>=$lbw_config_v4){      //这里判断体写v4规则
                    $data_vth['lbw_tuijianren']=$user_id;   //这判断体里写v4规则
                    $data_cr_vtw['lbw_viplevel']=3;
                    D('User')->where($data_vth)->save($data_cr_vtw);
                }else{       //这里判断体写v2规则
                    $data_vth['lbw_tuijianren']=$user_id;   //这判断体里写v2规则
                    $data_cr_vto['lbw_viplevel']=1;
                    D('User')->where($data_vth)->save($data_cr_vto);
                }
            }
        }
            //用户等级检测完毕the end
           // $user_tj=$User_a[$i]['tuijianrenku'];
           // $user_tjk=explode(',',$user_tj);
           // $tjk_total=count($user_tjk);
           // for($o=0;$o<$tjk_total;$o++){
           //     $lixi_chaxun['dk_lbw_vipid']=$user_tjk[$o];
           //     $chaxun_lixi_sj=D('UserLixi')->where($lixi_chaxun)->select();
           //
          //  }
          //  $data_tg_lixi['sf_jy_status']=array('NEQ',6);
       // $data_tg_lixi['sf_jy_status']=array('NEQ',3);

        //推广利息发放系统正式开始
        $data_ra['sf_jy_status'] = array('NEQ', 3);
        $data_ra['sf_jy_status'] = array('NEQ', 6);
        $ee= D('UserLixi')->where($data_ra)->select();//拿出交易状态不为纠纷的利息订单
        $lixidd_js=count($ee);

        for($li=0;$li<$lixidd_js;$li++){
            $Lixi_user=$ee[$li]['dk_lbw_vipid'];
            $Lixi_dh=$ee[$li]['dk_sf_jydh'];
            Lixicreat($Lixi_user,$Lixi_dh);
        }



        //先为利息订单的会员的所有上级建立推广利息表函数
    function Lixicreat($yonghuId,$dh){
            $dato['id']=$yonghuId;   //构造查询上级数据
            $adbc=D('User')->where($dato)->select();  //拿到推荐人直属上级数据
            static $jb = 1;                     //订单属性定义为1
            $tjr_id=$adbc[0]['lbw_tuijianren']; //寻找上级的上级
            if($tjr_id!=0){                       //判断有没有上级
                $dodo['lixiff_dh']=$dh;
                $dodo['sjvip_id']=array('EQ',$tjr_id);                          //通过传入的利息单号检测利息表有没有一样的
                $c=D('UserTuilixi')->where($dodo)->find();  //拿走一样单号的数据,可能会有多条一样单号，但是针对会员id不一样
                if($c==''){  //计算数组长度
                    $sbsb['sjvip_id']=$tjr_id;
                    $sbsb['jidai_huiyuan']=$jb;
                    D('UserTuilixi')->add($sbsb);
                    $jb=$jb+1;
                    return Lixicreat($yonghuId);
                }else{
                    return Lixicreat($yonghuId);
                }
            }else{

                return 'admin';
            }
        }


        function Lixijisuan($yonghuId,$dh,$lixi_time,$lixi_total_day,$yuji_time,$xiajimoney,$jidai_huiyuan,$sf_jy_status)
        {
            $dato['lbw_tuijianren']=$yonghuId;
            $adbc=D('User')->where($dato)->select();
            static $jb = 1;
            $tjr_id=$adbc[0]['lbw_tuijianren'];
            if($tjr_id!=0){

                D('User')->where()->select();
                $jb=$jb+1;
                return Lixijisuan($tjr_id);
            }
            return $tjr_id;
        }

    }

    public function jiangJin(){
        //转换成树状列表

        $data_list = D('UserTuiguang')->select();
        $treelist =list_to_tree($data_list,'id','parentId');

        $list=$this->findChild($treelist);
        dump($list);
    }
    protected  function findChild($arr){
        static $tree=array();
        foreach ($arr as $key=>$val){
            $tree[]=$val;
            if (isset($val['_child'])){
                $this->findChild($val['_child']);
            }
        }
        return $tree;
    }
    //用户每月排单检测 暂做测试使用
    public function UserLeveL(){

        $data_ra['sf_jy_status'] = array('NEQ', 3);
        $data_ra['sf_jy_status'] = array('NEQ', 6);
        $ee= D('UserLixi')->where($data_ra)->select();//拿出交易状态不为纠纷的利息订单
        $lixidd_js=count($ee);
        $Lixi_user=$ee[0]['dk_lbw_vipid'];
        $Lixi_dh=$ee[0]['dk_sf_jydh'];
        Lixicreat($Lixi_user,$Lixi_dh,$lixidd_js);


        //先为利息订单的会员的所有上级建立推广利息表函数
        function Lixicreat($yonghuId,$dh){

            $dato['id']=$yonghuId;   //构造查询上级数据
            $adbc=D('User')->where($dato)->select();  //拿到推荐人直属上级数据
            static $jb = 1;                     //订单属性定义为1
            $tjr_id=$adbc[0]['lbw_tuijianren']; //寻找上级的上级
            if($tjr_id!=0){                       //判断有没有上级
                $dodo['lixiff_dh']=$dh;
                $dodo['sjvip_id']=array('EQ',$tjr_id);                          //通过传入的利息单号检测利息表有没有一样的
                $c=D('UserTuilixi')->where($dodo)->find();  //拿走一样单号的数据,可能会有多条一样单号，但是针对会员id不一样

                if($c==''){  //计算数组长度
                    $sbsb['sjvip_id']=$tjr_id;
                    $sbsb['jidai_huiyuan']=$jb;
                    D('UserTuilixi')->add($sbsb);
                    $jb=$jb+1;
                    return  Lixicreat($Lixi_user,$Lixi_dh);
                }else{
                    return  Lixicreat($Lixi_user,$Lixi_dh);
                }
            }else{

                return 'admin';
            }
        }

    }

    //短信验证码功能
    public function duanxin(){
        $statusStr = array(
            "0" => "短信发送成功",
            "-1" => "参数不全",
            "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
            "30" => "密码错误",
            "40" => "账号不存在",
            "41" => "余额不足",
            "42" => "帐户已过期",
            "43" => "IP地址限制",
            "50" => "内容含有敏感词"
        );
        $smsapi = "http://api.smsbao.com/";
        $user = "916137925"; //短信平台帐号
        $pass = md5("songjie19920607"); //短信平台密码
        $content="短信内容";//要发送的短信内容
        $phone = I('post.sjmobile');//要发送短信的手机号码
        $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
        $result =file_get_contents($sendurl) ;
        echo $statusStr[$result];
    }


//抢单列表
    public function qiangDan(){
        $uid = $this->is_login();

        $map['sf_jy_status'] = array('EQ', '8'); //禁用和正常状态
        $map['shensu_cl_zt']=array('EQ','1');
        $data_list = D('UserPipeioder')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->select();
        $page = new \Common\Util\Page(D('UserPipeioder')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
        $show = $page->show();
        $user_info = D('User')->where($con)->find($uid);
        $this->assign('meta_title', '获得帮助列表');
        $this->assign('user_id', $user_info['username']);
        $this->assign('user_username', $user_info['id']);
        $this->assign('avatar',$user_info['avatar']);
        $this->assign('show',$show);
        $this->assign('datalist',$data_list);
        $this->assign('user_time', $user_info['ctime']);
        $this->assign('user_jtmoney', $user_info['user_jt_money']);
        $this->assign('user_pda', $user_info['lbw_paidancount']);
        $this->assign('user_jt_ye',$user_info['user_jt_money']);
        $this->assign('user_dt_ye',$user_info['user_dt_money']);
        $this->display();
    }
//抢打款订单
    public function dkJiaoyi(){
        $user_id=$_GET['id']; //拿到用户id
        $user_dh=$_GET['dh']; //拿到单号
        $user_cx['id']=$user_id;
        $relname=D('User')->where($user_cx)->select(); //获取用户信息
        //开始构造查询数据
        $data_cx['dk_lbw_order_pipei']=$user_dh;  //构造查找数据单号
        $data_up['dk_lbw_vipid']=$user_id;      //构造用户id
        $data_up['dk_creattime']=date("Y-m-d H:i:s");;    //生成抢单创建时间
//        $data_up['dk_odr_ordernumber']='';  //主订单号初始化

        $data_sj['id']=$relname[0]['lbw_tuijianren'];
        $sj_mobile=D('User')->where($data_sj)->getField('mobile'); //上级电话

        $data_up['dk_dakuan_status']=0;  //打款状态初始化
        $data_up['dk_dakuan_img']='';  //打款截图初始化
        $data_up['fk_name']=$relname[0]['realname']; //真实姓名初始化
        $data_up['dk_bank_name']=$relname[0]['lbw_bankname'];
        $data_up['dk_bank_number']=$relname[0]['lbw_banknumber'];
        $data_up['dk_alipay']=$relname[0]['lbw_alipay'];
        $data_up['dk_peiduifs']=123;
        $data_up['dk_sj_mobile']=$sj_mobile;
        $data_up['dk_my_mobile']=$relname[0]['mobile'];
        $data_up['fk_pingzheng_zt']=0;
        $data_up['sk_pingzheng_zt']=0;
        $data_up['sf_jy_status']=0;
        $data_up['shensu_cl_zt']=0;
        D('UserPipeioder')->where($data_cx)->save($data_up);
        $this->success('抢单成功');
       
    }
//抢收款订单
    public function skJiaoyi(){
        $user_id=$_GET['id']; //拿到用户id
        $user_dh=$_GET['dh']; //拿到单号
        $user_cx['id']=$user_id;
        $relname=D('User')->where($user_cx)->select(); //获取用户信息
        $yue_money=$relname[0]['user_jt_money'];
        //开始构造查询数据
        $data_cx['dk_lbw_order_pipei']=$user_dh;  //构造查找数据单号
        $ifmoney=D('UserPipeioder')->where($data_cx)->getField('dk_money_total');
        if($relname[0]['user_jt_money']>=$ifmoney){

        //开始构造查询打款金额数据
        $tixianmn=D('UserPipeioder')->where($data_cx)->getField('dk_money_total');

        $data_sj['id']=$relname[0]['lbw_tuijianren'];
        $sj_mobile=D('User')->where($data_sj)->getField('mobile'); //上级电话

        $data_up['sk_lbw_vipid']=$user_id;
        $data_up['sk_money_total']=$tixianmn;
        $data_up['sk_name']=$relname[0]['realname'];
        $data_up['sk_skuan_status']=0;
        $data_up['sk_lbw_order_pipei']='';
        $data_up['sk_skuan_img']='';
        $data_up['sk_bank_name']=$relname[0]['lbw_bankname'];
        $data_up['sk_bank_number']=$relname[0]['lbw_banknumber'];
        $data_up['sk_alipay']=$relname[0]['lbw_alipay'];
        $data_up['sk_peiduifs']=123;
        $data_up['sk_sj_mobile']=$sj_mobile;
        $data_up['sk_my_mobile']=$relname[0]['mobile'];
        $data_up['fk_pingzheng_zt']=0;
        $data_up['sk_pingzheng_zt']=0;
        $data_up['sf_jy_status']=0;
        $data_up['shensu_cl_zt']=0;
        D('UserPipeioder')->where($data_cx)->save($data_up);
        $this->success('抢单成功');
        }else{
        $this->error('抢单失败,您的账户余额不足,不能抢提现订单!');
        }
    }
//每月打款时间检测功能模块
    public function mothJance(){
        $data['status']=array('NEQ',0);
        $a=D('User')->where($data)->select();
        $b=count($a);
       for($i=0;$i<$b;$i++){
           $user_cx['id']=$a[$i]['id'];
            $last_time=D('User')->where($user_cx)->getField('last_dk_time');
            $nowtime = date("Y-m-d H:i:s");
            $abb = date('Y-m-d H:i:s', strtotime("$nowtime-30 day"));
           if($last_time>$abb){  //之前日期大于等于 就会被封掉
               $date['status']=0;
               D('User')->where($user_cx)->save($date);
           }else{
               echo '正常';
           }
       }

    }

//静态收益明细
    public function jingTaisy(){
        $uid = $this->is_login();
        $map['sf_jy_status'] = array('NEQ',4);
        $map['sf_jy_status'] = array('NEQ',8); //禁用和正常状态
        $map['sf_jy_status'] = array('NEQ',3);
        $map['dk_lbw_vipid']=$uid;
        $data_list = D('UserLixi')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->select();
        $page = new \Common\Util\Page(D('UserLixi')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
        $show = $page->show();



        $user_info = D('User')->where($con)->find($uid);
        $this->assign('meta_title', '获得帮助列表');
        $this->assign('user_id', $user_info['username']);
        $this->assign('user_username', $user_info['id']);
        $this->assign('avatar',$user_info['avatar']);
        $this->assign('show',$show);
        $this->assign('datalist',$data_list);
        $this->assign('user_time', $user_info['ctime']);
        $this->assign('user_jtmoney', $user_info['user_jt_money']);
        $this->assign('user_pda', $user_info['lbw_paidancount']);
        $this->assign('user_djjt_ye',$user_info['user_jt_money_no']);
        $this->assign('user_jt_ye',$user_info['user_jt_money']);
        $this->assign('user_dt_ye',$user_info['user_dt_money']);
        $this->display();
    }
//动态收益明细    
    public function dongTaisy(){
        $uid = $this->is_login();
        $map['sf_jy_status'] = array('NEQ',4);
        $map['sf_jy_status'] = array('NEQ',3);
        $map['sf_jy_status'] = array('NEQ',8); //禁用和正常状态
        $data_list = D('UserTuilixi')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($map)->select();
        $page = new \Common\Util\Page(D('UserTuilixi')->where($map)->count(), C('ADMIN_PAGE_ROWS'));
        $show = $page->show();

        $user_info = D('User')->where($con)->find($uid);
        $this->assign('meta_title', '获得帮助列表');
        $this->assign('user_id', $user_info['username']);
        $this->assign('user_username', $user_info['id']);
        $this->assign('avatar',$user_info['avatar']);
        $this->assign('show',$show);
        $this->assign('datalist',$data_list);
        $this->assign('user_time', $user_info['ctime']);
        $this->assign('user_jtmoney', $user_info['user_jt_money']);
        $this->assign('user_pda', $user_info['lbw_paidancount']);
        $this->assign('user_jt_ye',$user_info['user_jt_money']);
        $this->assign('user_dt_ye',$user_info['user_dt_money']);
        $this->display();
    }
    
//忘记密码
    public function Wangji(){
        
        $this->display();
    }
//意见反馈
    public function fanKui(){
        $date['user_id']=I('post.username');
        $ab=D('Fankui')->where($date)->select();
        $a=count($ab);
        if($a<3) {
            $data['fankui']=I('post.fankui');
            $data['time']=date('Y-m-d H:i:s');
            $data['user_id']=I('post.username');
            D('Fankui')->add($data);
            $this->success('感谢您的建议,我们会尽快回复于您！', U('User/center'));
        }else{
            $this->error('错误！每月最多只能提交3次,请不要重复提交!', U('User/center'));
        }

    }

    //用户中心用户资料修改模块
    public function editUserInfo(){
        $uid = $this->is_login();
        $a=I('post.bank_name');
        $c=I('post.bank_number');
        $e=I('post.alipay');
        if($a != ''){
            $a=trim($a);
            $data['lbw_bankname']=$a;
            $bb=D('User')->where('id='.$uid)->save($data);
            if($bb>0){
                echo '修改成功,请刷新页面';
            }else{
                echo '修改失败';
            }
        }else if($c != ''){
            $c=trim($c);
            $data['lbw_banknumber']=$c;
            $bb=D('User')->where('id='.$uid)->save($data);
            if($bb>0){
                echo '修改成功,请刷新页面';
            }else{
                echo '修改失败';
            }
        }else{
            $e=trim($e);
            $data['lbw_alipay']=$e;
            $bb=D('User')->where('id='.$uid)->save($data);
            if($bb>0){
                echo '修改成功,请刷新页面';
            }else{
                echo '修改失败';
            }
        }

    }

public function bb(){

                                     echo '<script language="JavaScript">';
                                         echo ' window.setInterval(function(){';
                                        echo 'var abc={$sf.dk_lbw_order_pipei};';
                                        echo "abc = '&danhao='+abc;";
                                        echo " $.ajax({";
                                        echo 'type: "post",';
                                        echo 'url : "'."{:U('Home/User/dkCountDown')}".'",';
                                        echo " data:abc,";
                                        echo "success: function(response) {";
                                        echo "$('#jiaoyitime').html(response);";
                                        echo " }";
                                        echo "});";
                                        echo "},1000);";
                                         echo "</script>";

}
    //激活码转账模板
    public function jihuomazz(){
        $this->meta_title = '激活码转账';
        $uid = $this->is_login();
        $user_info = D('User')->where($con)->find($uid);
        $user_name=$user_info['username'];
        $data['yy_username']=$user_name;
        $data_sj = D('Jihuoma')->where($data)->select(); //拿到总数
        $data_total=count($data_sj);
        $this->assign('meta_title', '个人中心');
        $this->assign('user_id', $user_info['username']);
        $this->assign('user_username', $user_info['id']);
        $this->assign('user_time', $user_info['ctime']);
        $this->assign('user_jtmoney', $user_info['user_jt_money']);
        $this->assign('user_pda', $user_info['lbw_paidancount']);
        $this->assign('user_jt_ye',$user_info['user_jt_money']);
        $this->assign('user_dt_ye',$user_info['user_dt_money']);
        $this->assign('user_total',$data_total);
        $this->display();
    }
    //激活码转账
    public function jhmCZ(){
        $uid = $this->is_login();
        $User_name=trim(I('post.username'));  //拿到用户名
        $User_total=trim(I('post.total'));    //拿到需要转账
        $User_pwd=trim(I('post.lbw_twopwd', '', 'user_md5'));  //拿到二级密码
        $lbw_erjimima['id'] = $uid;
        $twopdw = D('User')->where($lbw_erjimima)->getField('lbw_twopwd'); //拿到二级密码
        $usernmaeTwo = D('User')->where($lbw_erjimima)->getField('username'); //拿到用户名
        $User_cx['yy_username']=$usernmaeTwo;  //用户名查询
        $ab=D('Jihuoma')->where($User_cx)->select();  //查询用户激活码余额
        $if_ab=count($ab);  //获取用户激活码数量
        $User_total=abs($User_total);
        if($if_ab <= 0){
            $this->error('错误，您的激活码剩余数量不足！', U('User/jihuomazz'));
        }
        if($twopdw != $User_pwd){
            $this->error('错误，您的二级密码输入错误！', U('User/jihuomazz'));
        }
        if($User_total > $if_ab){
            $this->error('错误，您的激活码剩余数量不足！', U('User/jihuomazz'));
        }

        $data_up['yy_username']=$User_name;
        $data_up['ord_username']=$usernmaeTwo;
        $data['yy_username']=$usernmaeTwo;
        $jihuoma=D('Jihuoma')->where($data)->limit($User_total)->save($data_up);
        $this->success('转账成功！'.$jihuoma, U('User/jihuomazz'));

        }




    //激活码转账明细
    public function jhmlist(){
        $this->meta_title = '激活码明细';
        $uid = $this->is_login();
        $user_info = D('User')->where($con)->find($uid);
        $user_name=$user_info['username'];

        $data['yy_username']=$user_name;
        $data_xy = D('Jihuoma')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($data)->order('id desc')->select();
        $page = new \Common\Util\Page(D('Jihuoma')->where($data)->count(), C('ADMIN_PAGE_ROWS'));

        $data_two['ord_username']=$user_name;
        $data_zc = D('Jihuoma')->page(!empty($_GET["p"])?$_GET["p"]:1, C('ADMIN_PAGE_ROWS'))->where($data_two)->order('id desc')->select();
        $page_two = new \Common\Util\Page(D('Jihuoma')->where($data_two)->count(), C('ADMIN_PAGE_ROWS'));
        
        $this->assign('meta_title', '个人中心');
        $this->assign('user_id', $user_info['username']);
        $this->assign('user_username', $user_info['id']);
        $this->assign('user_time', $user_info['ctime']);
        $this->assign('user_jtmoney', $user_info['user_jt_money']);
        $this->assign('user_pda', $user_info['lbw_paidancount']);
        $this->assign('user_jt_ye',$user_info['user_jt_money']);
        $this->assign('user_dt_ye',$user_info['user_dt_money']);
        $this->assign('page',$page->show());
        $this->assign('page_two',$page_two->show());
        $this->assign('data_xy',$data_xy);
        $this->assign('data_zc',$data_zc);
        $this->display();
    }

    //v1会员利息检测
    public function vOneVip(){
        $datacig_lv['name'] = "LBW_ZTJ_PT_JL"; //获取利率设置
        $lbw_config_lx = D('SystemConfig')->where($datacig_lv)->getField('value');//获取利率设置

        $datacig_sx['name'] = "WEB_DTJJFD_VONE"; //获取获得上限设置
        $lbw_config_sx = D('SystemConfig')->where($datacig_sx)->getField('value');//获取获得上限设置

        $data['lbw_viplevel']=array('eq',0);
        $data['status']=array('eq',0);
        $v1_user=D('User')->where($data)->select(); //拿到所有正常v1会员
        $total=count($v1_user); //计算会员数量
        for($i=0;$i<$total;$i++){
            $data_lixi['tjr_username']=$v1_user[$i]['username'];
            $data_lixi['zhituijiang_zt']=array('eq',0);
            $data_lixi['jiaoyi_zt']=array('eq',2);
            $lixi_dd=D('UserTemppipeiorder')->where($data_lixi)->select(); //拿到利息订单
            $lixi_total=count($lixi_dd);
            $lixi_ze=0;
            for($o=0;$o<$lixi_total;$o++){
                $lixi_ze=$lixi_ze+$lixi_dd[$o]['total_forever']*$lbw_config_lx; //奖金
                $lixidh=$lixi_dd[$o]['lbw_order_pipei']; //单号
                $lixi_username=$lixi_dd[$o]['username']; //拿到用户名
                

            }
        }
    }
    //利息发放
    public function payInterest(){
        //设置array数组
        $configArr = array(
            '2' => array(
                'limitMoney' => 10000,
                'level' => array(
                    '1' => 0,
                    '2' => 0.2,
                    '3' => 0.1,
                    '4' => 0.08,
                    '5' => 0.03,
                    True => 0.03,
                )
            ),
            '3' => array(
                'limitMoney' => 15000,
                'level' => array(
                    '1' => 0,
                    '2' => 0.2,
                    '3' => 0.1,
                    '4' => 0.08,
                    '5' => 0.03,
                    True => 0.03,
                )
            ),
            '4' => array(
                'limitMoney' => 20000,
                'level' => array(
                    '1' => 0,
                    '2' => 0.2,
                    '3' => 0.1,
                    '4' => 0.08,
                    '5' => 0.03,
                    True => 0.03,
                )
            ),
        );
        $pay  = new \ZL\AutoPay(2, false, $configArr);//订单查找的状态，修改的状态 默认false不修改， 配置数组
        $pay->payInterest();
    }


//最底层
}

  /*  function getTree($data, $pId)
    {
       $html = '';
         foreach($data as $k => $v)
      {
        if($v['id'] == $pId)
        {         //父亲找到儿子
            $html .= "<li>".$v['username'];
            $html .= getTree($data, $v['lbw_tuijianren']);
            $html = $html."</li>";
        }
    }
    return $html ? '<ul>'.$html.'</ul>' : $html ;
}

    echo getTree($c, 0);




   function find_parent($ar, $id='id', $pid='pid') {
        foreach($ar as $v) $t[$v[$id]] = $v;
        foreach ($t as $k => $item){
            if( $item[$pid] ){
                if( ! isset($t[$item[$pid]]['parent'][$item[$pid]]) )
                    $t[$item[$id]]['parent'][$item[$pid]] =& $t[$item[$pid]];
            }
        }
        return $t;
    }



    function find_child($ar, $id='id', $pid='pid') {
        foreach($ar as $v) $t[$v[$id]] = $v;
        foreach ($t as $k => $item){
            if( $item[$pid] ) {
                $t[$item[$pid]]['child'][$item[$id]] =& $t[$k];
            }
        }
        return $t;
    }

    $p = find_parent($as, 'id', 'lbw_tuijianren');
    $c = find_child($as, 'id', 'lbw_tuijianren');


    */




//
 //       echo header("Content-type: text/html; charset=utf-8");
  //      echo '<pre>'.var_dump($p).'<pre>';
 //   echo '<pre>'.var_dump($c).'<pre>';

//申诉框架收款
  //  public function sfshensu(){
 //       $uid = $this->is_login();
//        $dd=$_GET['dd'];
 //       $this->assign('lbwshensu',$dd);
//        $this->display();
//    }
//    //申诉付款
  //  public function sfshensutwo(){
 //       $uid = $this->is_login();
 //       $dd=$_GET['dd'];
 //       $this->assign('lbwshensu',$dd);
  //      $this->display();
  //  }
